007 2852 001
User Manual: 007-2852-001
Open the PDF directly: View PDF
.
Page Count: 428
OpenGL Optimizer™
Programmer’s Guide:
An Open API for
Large-Model Visualization
Document Number 007-2852-001
CONTRIBUTORS
Written by Leif Wennerberg
Illustrated by Dany Galgani and Martha Levine
Edited by Christina Cary
Engineering contributions by Brian Cabral, Michael Hopcroft, Zi-Cheng Liu, Trina
Roy, Tonia Spyridi, and Julie Yen,
© 1997, Silicon Graphics, Inc.— All Rights Reserved
The contents of this document may not be copied or duplicated in any form, in whole
or in part, without the prior written permission of Silicon Graphics, Inc.
RESTRICTED RIGHTS LEGEND
Use, duplication, or disclosure of the technical data contained in this document by
the Government is subject to restrictions as set forth in subdivision (c) (1) (ii) of the
Rights in Technical Data and Computer Software clause at DFARS 52.227-7013
and/or in similar or successor clauses in the FAR, or in the DOD or NASA FAR
Supplement. Unpublished rights reserved under the Copyright Laws of the United
States. Contractor/manufacturer is Silicon Graphics, Inc., 2011 N. Shoreline Blvd.,
Mountain View, CA 94043-1389.
IRIS, OpenGL, Silicon Graphics, and the Silicon Graphics logo are registered
trademarks, ImageVision, Inventor, IRIS InSight, IRIS Performer, IRIX, Open
Inventor, OpenGL Optimizer, and Performer are trademarks, and Silicon Surf is a
service mark of Silicon Graphics, Inc. MIPSPro is a trademark of MIPS Technologies,
Inc. Alias is a registered trademark, and Alias|Wavefront is a trademark, of
Alias|Wavefront, a division of Silicon Graphics Limited. SDRC is a registered
trademark of Structural Dynamics Research Corporation. X Window System is a
trademark of Massachusetts Institute of Technology. Motif is a trademark of the
Open Software Foundation, Inc.
OpenGL Optimizer™ Programmer’s Guide: An Open API for Large-Model
Visualization
Document Number 007-2852-001
List of Chapters
About This Guide xxvii
PART I
Getting Started
3
1.
Overview of OpenGL Optimizer
2.
Installing, Compiling, and Running 17
3.
Basic I/O Tools: The Application viewDemo 29
4.
Scene Graph Tuning With the optimizeDemo Application 61
PART II
High-Level Strategic Tools for Fast Rendering
5.
Sending Efficient Graphics Data to the Hardware 93
6.
Rendering Appropriate Levels of Detail
7.
Culling Unneeded Objects From the Scene Graph 123
8.
Organizing the Scene Graph Spatially 139
PART III
9.
10.
PART IV
111
Specific Tools for Fast Rendering
Interactive Highlighting and Manipulating
155
Efficient High-Quality Lighting Effects: Reflection Mapping 169
Managing and Rendering Higher-Order Geometric Primitives
11.
Higher-Order Geometric Primitives and Discrete Meshes 183
12.
Creating and Maintaining Surface Topology 269
13.
Rendering Higher-Order Primitives: Tessellators 285
iii
List of Chapters
PART V
Traversers, Low-Level Geometry Processing, and Multiprocessing
14.
Traversing a Large Scene Graph 313
15.
Manipulating Triangles and Rebuilding Renderable Objects 327
16.
Managing Multiple Processors 339
PART VI
Utilities and Troubleshooting
17.
Utilities 365
18.
Trouble Shooting 377
Glossary 383
Index
iv
387
Table of Contents
List of Figures
xxiii
List of Tables xxv
0.
PART I
1.
2.
About This Guide xxvii
Audience for This Guide xxvii
How to Use This Guide xxviii
What This Guide Contains xxviii
Recommended Reference Materials xxxi
Silicon Graphics Publications xxxi
Third-Party Publications xxxi
Conventions Used in This Guide xxxii
Getting Started
Overview of OpenGL Optimizer 3
Difficulties With Visualizing Large CAD Datasets
How OpenGL Optimizer Helps 5
Graphics Pipeline 6
Bottlenecks in the Pipeline 7
Tools to Optimize the Generate Stage 8
Tools to Optimize the Traversal Stage 11
Tools to Optimize the Transform Stage 12
Optimal Use of Rasterization Hardware 15
4
Installing, Compiling, and Running 17
Installing the Library and Supporting Software 17
Environment Variables to Set Before Compiling an Application
19
v
Table of Contents
Sample Applications 20
Running a Sample Application 20
viewDemo Application 20
viewXmDemo Application 21
xdemo Application 21
optimizeDemo Application 22
mergeLODDemo 22
repTest Application 22
topoTest Application 22
opviz Application 23
zebraFly Application 23
Simple First Program 24
Simple Program Code 24
Compiling and Running the Simple Program
3.
vi
27
Basic I/O Tools: The Application viewDemo 29
Always First: Call opInit() 29
Reading and Writing Scene-Graph Files: The Extendable Loading Class opGenLoader
30
Saving a Scene Graph to a File 31
File Format Conversions 31
Class Declaration for opGenLoader 31
Main Features of the Methods in opGenLoader 32
Adding a Scene Graph Loader 32
Viewing Class: opViewer 33
Class Declaration for opViewer 35
Main Features of the Methods in opViewer 37
Basic Tools for Rendering Implementations: opKeyCallback and opDrawImpl 38
Class Declaration for opDrawImpl 38
Main Features of the Methods in opDrawImpl 39
Default opDrawImpl for opViewer: opDefDrawImpl 40
Class Declaration for opDefDrawImpl 40
Main Features of the Methods in opDefDrawImpl 40
opDefDrawImpl Keybindings 41
Table of Contents
Application viewDemo: A First Look in the Toolkit 42
Analogous X Window and Motif Applications 43
Compiling and Running viewDemo 43
viewDemo Code 44
4.
PART II
5.
Scene Graph Tuning With the optimizeDemo Application 61
General Features of Values Returned by Scene Graph Tools 62
Compiling and Running optimizeDemo 62
optimizeDemo Code 64
High-Level Strategic Tools for Fast RenderingChapter 8
Sending Efficient Graphics Data to the Hardware 93
Display Lists 94
Vertex Arrays 95
Shortening Representations of Surface Normal Data 96
Avoiding OpenGL Mode Switching 96
Removing Color Bindings 96
Removing csAppearance Effects 97
Class Declaration for opCollapseAppearances 97
Main Features of the Methods in opCollapseAppearance
Simplifying a Scene Graph: opFlattenScene() 98
97
vii
Table of Contents
Creating OpenGL Connected Primitives 100
Features of Trifans and Tristrips 100
How Trifans and Tristrips Are Constructed 101
How Attributes of Shared Vertices Are Managed 101
Strategies for Using Trifans, Tristips, or a Combination of Both 102
Count Vertices, Not Triangles, to Assess Graphic Pipeline Load 102
Merging Triangles Into Fans: opTriFanner 103
Class Declaration for opTriFanner 103
Main Features of the Methods in opTriFanner 104
Merging Triangles Into Strips: opTriStripper 105
Class Declaration for opTriStripper 105
Main Features of the Methods in opTriStripper 105
Tuning Triangle Strips: Fixing Tristrips That Are Too Short 106
Merging Triangles Into Both Strips and Fans: opTriFanAndStrip 107
Class Declaration for opTriFanAndStrip 107
Main Features of the Methods in opTriFanAndStrip 108
Merging Triangles Using Multiple Processors: opMPTriFanAndStrip 109
Class Declaration for opMPTriFanAndStrip 109
Main Features of the Methods in opMPTriFanAndStrip 110
Observing Trifans and Tristrips: opColorizeStrips() 110
6.
viii
Rendering Appropriate Levels of Detail 111
Overview of Simplification Tools 111
Simplifier Classes 112
Levels of Detail 112
LOD Insertion Tools 113
opSimplify: Base Class for Adding Level-of-Detail Nodes 113
Class Declaration for opSimplify 113
Main Features of the Methods in opSimplify: 114
Successive Relaxation Algorithm: opSRASimplify 115
Class Declaration for opSRASimplify 115
Main Features of the Methods in opSRASimplify 116
Table of Contents
Rossignac Simplification Algorithm: opLatticeSimplify 118
Class Declaration for opLatticeSimplify 118
Main Features of the Methods in opLatticeSimplify 118
Merging Graphs With Differing Levels of Detail: opMergeScenes
Class Declaration for opMergeScenes 121
Main Features of the Methods in opMergeScenes 121
7.
119
Culling Unneeded Objects From the Scene Graph 123
View-Frustum Culling 124
When to Use View-Frustum Culling 124
View-Frustum Culling and Pipeline Load Balancing 124
Spatialization to Balance Pipeline Load When View-Frustum Culling 125
Occlusion Culling 126
When to Use Occlusion Culling 126
Occlusion Culling and Pipeline Load Balancing 128
Changing the Fraction of the Bounding Box Required for Elimination 129
Rendering With View-Frustum and Occlusion Culling: opOccDrawImpl 129
Class Declaration for opOccDrawImpl 130
Main Features of the Methods in opOccDrawImpl 131
Key Bindings for opOccDrawImpl 132
View-Frustum and Occlusion Cull Draw Traversal: opDrawAction 133
Class Declaration for opDrawAction 133
Main Features of the Methods in opDrawAction 134
Tuning Tips for Occlusion Culling 134
Culling Takes Longer Than Rendering 134
Occluded Geometry Is Not Culled 135
Very Small Speedup and Fast Culling 135
Detail Culling 135
Class Declaration for opDetailSimplify 136
Main Features of the Methods in opDetailSimplify 136
Back-Face Culling 137
Two Lights Decreases Performance 138
Setting Backface Culling: opBackFaceCullScene() 138
ix
Table of Contents
8.
PART III
9.
x
Organizing the Scene Graph Spatially 139
Effect of Spatialization on Cull Traversals 139
Granularity Tradeoffs 140
When to Spatialize 140
Spatialization Algorithm 140
Spatialization Control Parameters 141
Spatialization Classes 141
Spatialization Tool: opSpatialize 142
Class Declaration for opSpatialize 142
Main Features of the Methods in opSpatialize 143
Classes for Component Procedures of Spatialization 143
Spatializing a Scene Graph: opGeoSpatialize 144
Class Declaration for opGeoSpatialize 146
Main Features of the Methods in opGeoSpatialize 146
Merging csGeoSets in a Scene Graph: opCombineGeoSets 147
Class Declaration for opCombineGeoSets 149
Main Features of the Methods in opCombineGeoSets 149
Spatializing a Single csShape: opTriSpatialize 150
Class Declaration for opTriSpatialize 152
Specific Tools for Fast Rendering
Interactive Highlighting and Manipulating 155
Overview of Highlighting and Picking 155
How Picking Can Accelerate Rendering Rates 156
Interaction With a Rendered Object: opPickDrawImpl 156
Class Declaration for opPickDrawImpl 157
Main Features of the Methods in opPickDrawImpl 158
Key Bindings for opPickDrawImpl 160
Scene Graph Modification: opPick 161
Class Declaration for opPick 162
Main Features of the Methods in opPick 163
Sample Use of opPick 165
Table of Contents
Node to Override Appearances: opHighlight 167
Class Declaration for opHighlight 167
Sample Use of opHighlight for Picking and Highlighting
10.
PART IV
11.
168
Efficient High-Quality Lighting Effects: Reflection Mapping 169
Simple Mapping: Remote View of a Remote Environment 170
Sphere Map 172
Gaussian Map 172
Accurate Mapping: Local View of a Local Environment 173
Cylinder Map 175
Reflection-Mapping Class: opReflMap 177
Class Declaration for opReflMap 177
Main Features of the Methods in opReflMap 179
Managing and Rendering Higher-Order Geometric Primitives
Higher-Order Geometric Primitives and Discrete Meshes 183
Features and Uses of Higher-Order Geometric Primitives 184
Reps Relationship to the Rendering Process 184
Trimmed NURBS 184
Necessary Objects Used by Reps 185
Pi 185
Classes for Points 185
Classes for Scalar Functions 186
Class Declaration for opScalar 186
Class Declaration for opCompositeScalar 186
Main Features of the Methods in opCompositeScalar 186
Trigonometric Functions 187
Polynomials 187
Class Declaration for opPolyScalar 187
Matrix Class: opFrame 188
Class Declaration for opFrame 188
xi
Table of Contents
Geometric Primitives: The Base Class opRep and the Application repTest
Class Declaration for opRep 191
Main Features of the Methods in opRep 191
Planar Curves 192
Mathematical Description of a Planar Curve 192
Class Declaration for opCurve2d 194
Main Features of the Methods in opCurve2d 195
Lines in the Plane 196
Class Declaration for opLine2d 196
Main Features of the Methods in opLine2d 197
Circles in the Plane 197
Main Features of the Methods in opCircle2d 198
Superquadric Curves: opSuperQuadCurve2d 199
Class Declaration for opSuperQuadCurve2d 201
Main Features of the Methods in opSuperQuadCurve2d 201
Hermite-Spline Curves in the Plane 202
Class Declaration for opHsplineCurve2d 203
NURBS Briefly 204
OpenGL Optimizer NURBS Classes 205
NURBS Control Parameters 205
NURBS Elements That Determine the Control Parameters 205
Knot Points 206
Control Points 206
Weights for Control Points 207
Features of NURBS and Bezier Curves 207
NURBS Curves in the Plane 208
Class Declaration for opNurbCurve2d 208
Main Features of the Methods in opNurbCurve2d 209
The Equation Used to Calculate a NURBS Curve 210
An Alternative Equation for a NURBS Curve 210
Discrete Curves in the Plane 211
Class Declaration for opDisCurve2d 212
Main Features of the Methods in opDisCurve2d 213
xii
189
Table of Contents
Spatial Curves 214
Lines in Space 214
opOrientedLine3d 215
Circles in Space 215
Superquadrics in Space 215
Hermite Spline Curves in Space 216
NURBS Curves in Space 216
Curves on Surfaces: opCompositeCurve3d 216
Class Declaration for opCompositeCurve3d 217
Main Features of the Methods in opCompositeCurve3d 217
Discrete Curves in Space 217
Example of Using opDisCurve3d and opHsplineCurve3d 218
xiii
Table of Contents
Parametric Surfaces 219
Mathematical Description of a Parametric Surface 220
Defining Edges of a Parametric Surface: Trim Loops and Curves 221
Adjacency Information: opEdge 223
Class Declaration for opEdge 223
Base Class for Parametric Surfaces: opParaSurface 224
Class Declaration for opParaSurface 224
Main Features of the Methods in opParaSurface 226
opPlane 228
Class Declaration for opPlane 229
Main Features of the Methods in opPlane 230
opSphere 231
Class Declaration for opSphere 232
Main Features of the Methods in opSphere 232
Typical Instantance of a Trimmed Parametric Surface: an opSphere 233
opCylinder 234
Class Declaration for opCylinder 235
Main Features of the Methods in opCylinder 235
opTorus 236
Class Declaration for opTorus 237
Main Features of the Methods in opTorus 237
opCone 238
Class Declaration for opCone 239
Main Features of the Methods in opCone 239
Swept Surfaces 240
Orientation of the Cross Section 242
Class Declaration for opSweptSurface 242
Main Features of the Methods in opSweptSurface 243
opFrenetSweptSurface 244
Class Declaration for opFrenetSweptSurface 244
Main Features of the Methods in opFrenetSweptSurface 244
Making a Modulated Torus With opFrenetSweptSurface 245
Ruled Surfaces 246
xiv
Table of Contents
Class Declaration for opRuled 247
Coons Patches 248
Class Declaration for opCoons 250
NURBS Surfaces 251
Class Declaration for opNurbSurface 252
Main Features of the Methods in opNurbSurface 253
Indexing Knot Points and the Control Hull 253
The Equation Used to Calculate a NURBS Surface 255
An Alternative Equation for a NURBS Surface 255
Sample of a Trimmed opNurbSurface From repTest 256
Hermite-Spline Surfaces 258
Class Declaration for opHsplineSurface 259
Main Features of the Methods in opHsplineSurface 260
opCuboid 260
Class Declaration for opCuboid 260
Regular Meshes and Discrete Surfaces 262
Discrete Surface Base Class: opDisSurface 262
Making a Discrete Surface and Other Mesh Objects: opRegMesh
Class Declaration for opRegMesh 263
Main Features of the Methods in opRegMesh 265
An opConstant opRegMesh: Data for opviz 267
An opVariable opRegMesh: Data for opviz 268
An opVariable opRegMesh: Data for opviz 268
12.
262
Creating and Maintaining Surface Topology 269
Overview of Topology Tasks 270
xv
Table of Contents
Summary of Scene Graph Topology: opTopo 270
Building Topology: Computing and Using Connectivity Information 273
Building Topology Incrementally: A Single-Traversal Build 273
Building Topology From All the Surfaces in a Scene Graph: A Two-Traversal
Build 274
Building Toplogy From a List of Surfaces 274
Building Toplogy “by Hand”: Imported Surfaces 274
Summary of Topology Building Strategies 275
Reading and Writing Topology Information: Using optimizeDemo 276
Class Declaration for opTopo 278
Main Features of the Methods in opTopo 279
Consistent Vertices at Boundaries: opBoundary 280
Class Declaration for opBoundary 281
Main Features of the Methods in opBoundary 282
Collecting Connected Surfaces: opSolid 283
Class Declaration for opSolid 283
Main Features of the Methods in opSolid 283
284
13.
xvi
Rendering Higher-Order Primitives: Tessellators 285
Features of Tessellators 286
Tessellators for Varying Levels of Detail 287
Details of Figure 13-2 288
Tessellators Act on a Whole Graph or Single Node 288
Tessellators and Topology: Managing Cracks 288
Base Class opTessellateAction 289
Tessellating a Scene Graph With Several Tessellators 289
Class Declaration for opTessellateAction 290
Main Features of the Methods in opTessellateAction 290
Tessellating Curves in Space 292
Class Declaration for opTessCurve3dAction 292
Main Features of the Methods in opTessCurve3dAction 293
Table of Contents
opTessCuboidAction 294
Class Declaration for opTessCuboidAction 294
Main Features of the Methods in opTessCuboidAction 294
Tessellating Parametric Surfaces 295
opTessParaSurfaceAction 295
Class Declaration for opTessParaSurfaceAction 296
Main Features of the Methods in opTessParaSurface 297
Sample From repTest: Tessellating and Rendering a Sphere 298
opTessNurbSurfaceAction 301
Tessellating a Regular Mesh 301
Visualizing Scalar-Valued Functions 301
Visualizing Vector-Valued Functions 302
opTessIsoAction 302
Class Declaration for opTessIsoAction 302
Main Features of the Methods in opTessIsoAction 303
opTessSliceAction 303
Class Declaration for opTessSliceAction 303
Main Features of the Methods in opTessSliceAction 304
opTessVecAction 305
Class Declaration for opTessVecAction 305
Main Features of the Methods in opTessVecAction 305
opTessVec2dAction and opTessVec3dAction 306
Sample Mesh Tessellation: opviz and opVizViewer 306
opVizViewer 307
Key Bindings for opVizViewer 307
opviz’s Main Routine 308
Initializing a Tessellator 308
opviz Tessellation and Thread Manager Calls 309
xvii
Table of Contents
PART V
xviii
Traversers, Low-Level Geometry Processing, and Multiprocessing
14.
Traversing a Large Scene Graph 313
Traversals and Callbacks: General Features 314
Depth-First Traversal Sequence 314
Breadth-First Traversal Sequence 316
Callbacks During a Traversal 317
Controlling a Traversal With the Callback Return Value opTravDisp 317
Specifying Deletion of Storage of Traversal Objects: opActionDisp 318
Depth-First Traversals: opDFTravAction 318
Class Declaration for opDFTravAction 318
Main Features of the Methods in opDFTravAction 319
Breadth-First Traversals: opBFTravAction 320
Class Declaration for opBFTravAction 320
Main Features of the Methods in opBFTravAction 321
Sample Traversal Function From the Application optimizeDemo 322
Traversing a Scene Graph and Applying a csDispatch: opDispatchAction 325
Main Features of the Methods in opDispatchAction 325
15.
Manipulating Triangles and Rebuilding Renderable Objects 327
Overview of Low-Level Geometry Tools 327
Low-Level Tools Class Heirarchy 328
Decompose csGeoSets Into Constituent Triangles: opGeoConverter 329
Class Declaration for opGeoConverter 330
Main Features of the Methods in opGeoConverter 331
Specify Coloring of New csGeoSets: opColorGenerator 332
Class Declaration for opColorGenerator 332
Main Features of the Methods in opColorGenerator 332
Table of Contents
Build New csGeoSets 333
Geometry-Building Base Class: opGeoBuilder 333
Class Declaration for opGeoBuilder 333
Main Features of the Methods in opGeoBuilder 334
Sets of Triangles From Individual Triangles: opTriSetBuilder 335
Class Declaration for opTriSetBuilder 335
Main Features of the Methods in opTriSetBuilder 336
Sets of Triangle Fans From Triangles: opTriFanSetBuilder 337
Class Declaration for opTriFanSetBuilder 337
Main Features of the Methods in opTriSetBuilder 338
Sets of Triangle Strips From Triangles: opTriStripSetBuilder 338
Main Features of the Methods in opTriFanSetBuilder 338
16.
Managing Multiple Processors 339
MP Control Tasks and Related Classes 340
Overview of the Thread Manager 341
Sequence of Events for Thread Management 341
Managing Interprocess Dependencies 341
Classes for Scheduling and Defining Tasks 342
Thread Manager: opThreadMgr 342
Class Declaration for opThreadMgr 343
Main Features of the Methods in opThreadMgr 344
Scheduling Methods 344
Interprocess Control Methods 345
Difference Between Interprocess Control Methods 346
Defining Tasks for a Thread Manager 347
opActionInfo Holds Thread Information 347
opFunctionAction: One Task, One Process 348
Class Declaration for opFunctionAction 348
Main Features of the Methods in opFunctionAction 348
opMPFunAction: One Task, Many Processes 349
Main Features of the Methods in opMPFunAction 350
opMPFunListAction: Many Tasks, Many Processes 351
Main Features of the Methods in opMPFunListAction 352
xix
Table of Contents
Coordinating Threads That Change a Scene Graph: opTransactionMgr
Class Declaration for opTransactionMgr 354
Main Features of the Methods in opTransactionMgr 355
opTransaction 356
Class Declaration for opTransaction 356
Main Features of the Methods in opTransaction 357
opCommit(), opBlockingCommit(), and opSync() 357
Low-Level Multiprocess Tools 358
opLock 358
Class Declaration for opLock 358
Main Features of the Methods in opLock 359
Mutual Exclusion Within a Code Block: opMutex 359
opSemaphore 360
Class Declaration for opSemaphore 360
Main Features of the Methods in opSemaphore 360
Making Processes Wait on a Task: opTaskBlock 361
Class Declaration for opTaskBlock 361
Main Features of the Methods in opTaskBlock 361
Implementing a Condition Variable: opBlockingCounter 362
Main Features of the Methods in opBlockingCounter 362
PART VI
17.
xx
353
Utilities and Troubleshooting
Utilities 365
Error Handling and Notification 366
Performance Indicators 367
opStopWatch 367
opPerfPlot 367
dvector: A Template Class for Dynamic Arrays of Contiguous Elements
Viewing a Scene Graph 368
368
Table of Contents
Gathering Triangle Statistics 369
Getting Statistics About Individual Elements: opTriStatsDispatch
Class Declaration for opTriStatsDispatch 370
Main Features of the Methods in opTriStatsDispatch 371
Getting Statistics About a Scene Graph: opTriStats 371
Main Features of the Methods in opTriStats 371
Example of Using an opTriStats 372
Displaying Node Information 373
Class Declaration for opInfoNode 373
Main Features of the Methods in opInfoNode 373
Example of Using an opInfoNode 374
Observing OpenGL Modes 374
Class Declaration for opGLSpyNode 374
Main Features of the Methods in opGLSpyNode 374
Example of Using an opGLSpyNode 375
Command-Line Parser: opArgParser 375
Class Declaration for opArgParser 376
Main Features of the Methods in opArgParser 376
18.
Troubleshooting 377
Compiler Warning Messages 377
Run-Time Warning Messages 378
Tuning the Scene Graph Database 378
Reduce the Polygon Count 379
Combine Small csGeoSets 379
Spatialize to Facilitate View Frustum and Occlusion Culling
Use Level-of-Detail Nodes 381
Tessellation Problems 382
No Triangles 382
Slow Processing 382
369
380
Glossary 383
Index 387
xxi
List of Figures
Figure 1-1
Figure 1-2
Figure 1-3
Figure 1-4
Figure 1-5
Figure 1-6
Figure 1-7
Figure 1-8
Figure 1-9
Figure 3-1
Figure 3-2
Figure 4-1
Figure 5-1
Figure 5-2
Figure 6-1
Figure 6-2
Figure 7-1
Figure 7-2
Figure 8-1
Figure 8-2
Figure 8-3
Figure 10-1
Interior Parts From a CAD Model That Can Be Manipulated
Interactively Using OpenGL Optimizer (Data courtesy of SDRC™) 4
OpenGL Optimizer Architecture 6
Higher-Order Surface Representations With Trimmed Pieces 9
NURBS Surfaces Deformed From One Another by Moving Two Control
Points 10
Shell That Occludes the Objects Shown in Figure 1-1 (Data courtesy of
SDRC™) 12
Simplification From 4629 to 2002 to 483 Triangles 13
Tessellations of a Higher-Order Surface: 16,544 to 120 triangles 14
TubeLighting: Note Differences of Lights on Hood and Roof Compared
to Figure 1-9 (Data courtesy of Alias|Wavefront™) 15
TubeLighting: Note Differences of Lights on Hood and Roof Compared
to Figure 1-8 (Data courtesy of Alias|Wavefront) 15
opViewer Scene Graph 33
A Model Rendered by the Application viewDemo 42
Simplifying a Model With optimizeDemo 63
Flattening A Scene Graph Removes Interior Nodes 99
Construction of Triangle Fan (left) and Triangle Strip (right) 101
opSRASimplify: Original Model; A Target of 30% With a Feature Angle
of 10°; A Target of 5% With a Feature Angle of 100°. 117
Merging Two Scene Graphs 120
Combined Effects of View Frustum and Occlusion Culling 127
Back Faces, Back-Face Culling, and Two-Sided Lighting Effects 137
Organizing and Combining csGeoSets With opGeoSpatialize 145
Combining csGeoSets with opCombineGeoSets 148
Creating a Spatialized Graph From the csGeoSet in One csShape 151
Reflection-Map Geometry: Remote Viewer, Remote Environment 171
xxiii
List of Figures
Figure 10-2
Figure 10-3
Figure 10-4
Figure 10-5
Figure 11-1
Figure 11-2
Figure 11-3
Figure 11-4
Figure 11-5
Figure 11-6
Figure 11-7
Figure 11-8
Figure 11-9
Figure 11-10
Figure 11-11
Figure 11-12
Figure 11-13
Figure 11-14
Figure 11-15
Figure 11-16
Figure 11-17
Figure 11-18
Figure 11-19
Figure 12-1
Figure 12-2
Figure 13-1
Figure 13-2
Figure 14-1
Figure 14-2
Figure 15-1
xxiv
Reflection-Map Geometry: Local Viewer, Local Environment 174
Cylinder-Map Images: Note How Lighting Differs From View in (Data
courtesy of Alias|Wavefront) 175
Cylinder-Map Images: Note How Lighting Differs From View in
Figure 10-3 (Data courtesy of Alias|Wavefront) 175
Viewing Configuration for the Cylinder Map 176
Class Hierarchy for Higher-Order Primitives 190
Parametric Curve: Parameter Interval (0,1). 193
Line in the Plane Parameterization 196
Circle in the Plane Parameterization 197
Superquadric Curve’s Dependence on the Parameter α. 200
Hermite Spline Curve Parameterization 202
Discrete Curve Definition 211
Parametric Surface: Unit-Square Coordinate System 220
Trim Loops and Trimmed Surface: Both Trim Loops Made of Four Trim
Curves 222
Plane Parameterization 228
Sphere Parameterization 231
Cylinder Parameterization 234
Torus Parameterization 236
Cone Parameterization 238
Swept Surface: Moving Reference Frame and Effect of Profile Function
241
Ruled Surface Parameterization 246
Coons Patch Construction 249
Nurb Surface Control Hull Parameterization 254
Hermite Spline Surface With Derivatives Specified at Knot Points 258
Topological Relations Maintained by Topology Classes 271
Consistently Tessellated Adjacent Surfaces and Related Objects 272
Class Hierarchy for Tessellators 286
Tessellations Varying With Changes in Control Parameter 287
Depth-First, Left-to-Right Traversal of a Simple Scene Graph 315
A Breadth-First Traversal of a Simple Scene Graph 316
Class Hierarchy of Geometry-Building Tools 328
List of Tables
Table 2-1
Table 12-1
Table 12-2
Table 12-3
Table 16-1
Table 17-1
Libaries Used by OpenGL Optimizer 18
Topology Building Methods 275
Adding Topology and Tessellations to .iv and .csb Files 277
Reading .csb Files: With and Without Tessellations 277
Modes of Executing Multithreaded Tasks and Their Action Objects 342
Error Priority Levels: Lowest to Highest 366
xxv
0. About This Guide
OpenGL Optimizer™ is a C++ toolkit for CAD applications. It enables interactive, rubust
visualization of large model databases. The set of tools includes the following features:
•
High-quality surface representations, that is, topologically consistent, parametric
definitions of surfaces
•
Tessellation
•
Simplification
•
Occlusion culling
•
Support for multiprocessor computing and advanced graphics hardware
This guide describes the various subsystems in the class library and how they work
together, and directs your attention to the important issues and tools you should
consider as you develop large-model visualization programs using OpenGL Optimizer.
This is not a reference manual but a guide. For complete details about elements of the
library, consult the reference pages and header files, and look at the example
applications.
Audience for This Guide
This book is intended for knowledgeable C and C++ CAD developers who understand
the basic concepts of OpenGL® and computer graphics.
To use OpenGL Optimizer effectively, you should also understand Cosmo3D. OpenGL
Optimizer extends Cosmo3D, which is built on OpenGL and specifies a scene-graph
application program interface, so a complete OpenGL Optimizer application will include
Cosmo3D calls. However, you do not need to understand OpenGL. Cosmo3D uses ideas
from both Open Inventor and IRIS Performer, so many features may be familiar to
users of these toolkits. See Cosmo 3D Programmer’s Guide.
xxvii
About This Guide
You will more easily understand the tools if you are familiar with scene graphs and
higher-order geometric primitives, such as NURBS. You need not know techniques for
large-model visualization, nor have more than a rudimentary knowledge of
multi-processor techniques.
How to Use This Guide
The OpenGL Optimizer tools are modular without strong interdependencies. After
familiarizing yourself with the topics in Part I, “Getting Started,” you should be able to
read profitably about any topic you pick from the table of contents. Cross-references
within discussions guide you to related material.
Not every feature in every header file is documented in this guide. Also, some elements
presented differ slightly from the header files, due to late changes in the software. For
further information about a specific class, see the man page for that class, which will be
in the form op*(3in), where op* is an OpenGL Optimizer class.
All classes and functions in the OpenGL Optimizer library have names that begin with
the characters op followed a string beginning with an upper-case letter.
All classes and functions in the Cosmo3D library have names that begin with the
characters cs followed a string beginning with an uppercase letter. Consult the Cosmo 3D
Programmer’s Guide for more information about any object whose name begins with cs.
What This Guide Contains
Part I, “Getting Started”
Chapter 1, “Overview of OpenGL Optimizer,”quickly summarizes the problems of large
CAD visualization, characterizes in general terms the rendering task that the OpenGL
Optimizer library facilitates, and surveys the tools OpenGL Optimizer provides to
address bottlenecks at each stage of the graphics pipeline.
Chapter 2, “Installing, Compiling, and Running,” provides elementary information you
need to use the library, briefly discusses sample applications, and presents a minimal first
program.
xxviii
What This Guide Contains
Chapter 3, “Basic I/O Tools: The Application viewDemo,” introduces you to the main
rendering tools.
Chapter 4, “Scene Graph Tuning With the optimizeDemo Application,” introduces you
to the main OpenGL Optimizer batch processing tools.
Part II, “High-Level Strategic Tools for Fast RenderingChapter 8,” describes complete
data processing methods for fast and coherent rendering of a large CAD database.
Chapter 5, “Sending Efficient Graphics Data to the Hardware,” discusses how to use
display lists, vertex arrays, smaller vertex-data formats, connected geometric primitives,
and scene-graph flattening.
Chapter 6, “Rendering Appropriate Levels of Detail,” discusses mesh simplifiers and a
tool to insert level-of-detail nodes in the scene graph.
Chapter 7, “Culling Unneeded Objects From the Scene Graph,” discusses view-frustum
culling, occlusion culling, and back-face culling.
Chapter 8, “Organizing the Scene Graph Spatially,” presents tools to reorganize the
triangles in a scene graph to increase rendering speed.
Part III, “Specific Tools for Fast Rendering,” presents tools for two useful rendering
tasks.
Chapter 9, “Interactive Highlighting and Manipulating,” describes how to interactively
highlight and manipulate objects in a scene.
Chapter 10, “Efficient High-Quality Lighting Effects: Reflection Mapping,” presents
good, approximate, fast lighting techniques, and techniques that provide very accurate
lighting for reliable visual examination of model surfaces.
Part IV, “Managing and Rendering Higher-Order Geometric Primitives,” presents the
set of tools for managing and rendering surfaces that are defined by mathematical
equations.
Chapter 11, “Higher-Order Geometric Primitives and Discrete Meshes,” describes
OpenGL Optimizer extensions to Cosmo3D, for example, parametric surfaces and
trimmed NURBS.
xxix
About This Guide
Chapter 12, “Creating and Maintaining Surface Topology,” describes tools to stitch
together geometric primitives so that images do not have artificial cracks or breaks.
Chapter 13, “Rendering Higher-Order Primitives: Tessellators,” presents the tools you
need to convert higher-order primitives into primitives that can be passed to the graphics
hardware.
Part V, “Traversers, Low-Level Geometry Processing, and Multiprocessing,” describes
tools that manipulate scene graph elements.
Chapter 14, “Traversing a Large Scene Graph,” describes tools that focus on scene-graph
manipulations.
Chapter 15, “Manipulating Triangles and Rebuilding Renderable Objects,” describes the
lower-level tools that perform the tasks discussed in Chapter 8.
Chapter 16, “Managing Multiple Processors,” describes the tools that allow you to easily
manipulate a scene graph with several processors and coordinate manipulations of the
scene graph.
Part VI, “Utilities and Troubleshooting,” describes tools and hints that are useful for
developing OpenGL Optimizer applications.
Chapter 17, “Utilities,” presents several tools, such as error handlers and timers, to help
polish an OpenGL Optimizer application.
Chapter 18, “Troubleshooting,” describes ways to avoid typical sticking points that occu
when developing an OpenGL Optimizer application.
This guide also includes a glossary.
xxx
Recommended Reference Materials
Recommended Reference Materials
Silicon Graphics Publications
The following are found in IRIS InSight™:
Cosmo 3D Programmer’s Guide (SGI_Developer bookshelf)
IRIS Performer Programming Guide (SGI_Developer bookshelf)
MIPS Compiling and Performance Tuning Guide (SGI_Developer bookshelf)
For information on dynamically shared objects (DSOs)
OpenGL on Silicon Graphics Systems (SGI_Developer bookshelf)
Third-Party Publications
Farin, Gerald. Curves and Surface for Computer Aided Geometric Design. San Diego, Calif.:
Academic Press, Inc., 1988.
D. Voorhies and J. Foran, “Reflection Vector Shading Hardware” in Computer Graphics
Proceedings, Annual Conference Series, ACM, 1994.
The OpenGL WWW Center at http://www.sgi.com/Technology/OpenGL.
The following are all produced by Addison-Wesley Publishing:
Foley, J. D., A. vanDam, S. K. Feiner, and J. F. Hughes, Computer Graphics: Principles and
Practice. 1990.
Gamma, E., R. Helm, R. Johnson, J. Vlissides, Design Patterns: Elements of Reusable
Object-Oriented Software, 1995.
Kilgard, M. J., Programming OpenGL for the X Window System, 1996. (Also known as “the
Green book.”)
OpenGL Architecture Review Board, M. Woo, J. Neider, and T. Davis, OpenGL
Programming Guide, Second Edition, 1997. (Also known as “the Red book.”)
xxxi
About This Guide
OpenGL Architecture Review Board, OpenGL Reference Manual, 1992. (Also known as
“the Blue book.”)
Watt, A. and M. Watt, Advanced Animation and Rendering Techniques: Theory and Practice,
1992. Note Chapter 6, “Mapping Techniques: Texture and Environment Mapping.”
Wernecke, J., The Inventor Mentor: Programming Object-Oriented 3D Graphics with Open
Inventor, 1994.
Wernecke, J., The Inventor Toolmaker, 1994.
Conventions Used in This Guide
These type conventions and symbols are used in this guide:
Bold
C++ class names, C++ member functions, C++ data members, and
function names.
Italics
Filenames, manual/book titles, new terms, and variables.
Fixed-width type
Code.
Bold fixed-width type
Keyboard input keys.
ALL CAPS
Environment variables, defined constants.
() (Bold Parentheses)
Follow function names. They surround function arguments if needed
for the discussion or are empty if not needed in a particular context.
xxxii
PART ONE
Getting Started
I
The first two chapters in this section introduce OpenGL Optimizer features,
show you how to link to the library, and discuss sample applications. The next
two chapters disscuss in detail two of the sample applications and introduce
much of the OpenGL Optimizer library.
These are the chapters in Part One:
Chapter 1, “Overview of OpenGL Optimizer”
Chapter 2, “Installing, Compiling, and Running”
Chapter 3, “Basic I/O Tools: The Application viewDemo”
Chapter 4, “Scene Graph Tuning With the optimizeDemo Application”
Chapter 1
1. Overview of OpenGL Optimizer
OpenGL Optimizer is a C++ library, a toolkit that facilitates the development of a new
class of applications for interacting with large CAD models characterized by millions of
triangles. OpenGL Optimizer eases digital prototyping and enables visualizing models
at any scale, from individual parts, to subassemblies, to an entire, complex mechanism.
These features allow you, for example, to use accurate, high-quality images to integrate
the design of all the components of an automobile
OpenGL Optimizer is built on Cosmo3D and OpenGL, and you can use all three libraries
concurrently. Thus, you can mix Cosmo3D and OpenGL calls with OpenGL Optimizer
calls to render essential portions of very large scene graphs.
To provide you with programming flexibility, OpenGL Optimizer includes high-level
tools that reduce programming overhead for certain tasks: an occlusion culler and thread
management, for example. There are also lower-level tools if you want more direct
control of processing details. To encourage flexible programming, the toolkit is organized
into a collection of modules that cooperate but can also operate independently.
These topics are covered in this chapter:
•
“Difficulties With Visualizing Large CAD Datasets” on page 4
•
“How OpenGL Optimizer Helps” on page 5
3
Chapter 1: Overview of OpenGL Optimizer
Difficulties With Visualizing Large CAD Datasets
Interacting with large CAD datases is a powerful design technique. However, the
rendering tasks necessary to visualize a complex integrated design can be slow or
impossible without the data management techniques available in the OpenGL Optimizer
library.
For perspective on the scale of the rendering task, assume that the number of pixels per
triangle is, on average, ten. Then only about 100,000 triangles can appear at any instant
on a 1024 x 1024 screen. High-end graphics hardware can easily render frames with this
many triangles at 20 Hz, that is, at rates sufficient for continuous motions. However, a
large database may include millions of triangles, so less than one tenth of a model can be
visible at any time. Quickly finding the right set of triangles and producing rendering
commands is a central processing task for a CAD application and is a central purpose of
the OpenGL Optimizer library. Figure 1-1 shows the interior of a model that can be
manipulated with OpenGL Optimizer at interactive rates. The parts shown are those
hidden by the shell of the model; they are removed from the graphics pipeline by
occlusion culling when the model is viewed from outside.
Figure 1-1
Interior Parts From a CAD Model That Can Be Manipulated Interactively Using
OpenGL Optimizer (Data courtesy of SDRC™)
To accurately represent the surfaces in the design database requires selecting triangles
that provide appropriate detail without artificial cracks. To this end, OpenGL Optimizer
provides tools that provide controls over tessellation, mesh simplification, and surface
connectivity information, that is, topology.
4
How OpenGL Optimizer Helps
How OpenGL Optimizer Helps
OpenGL Optimizer provides tools to send only essential graphical information down the
graphics pipeline and to interact with the scene graph efficiently using multiple
processors.
To minimize the memory footprint of the scene graph, geometric objects can be
represented as abstract mathematical expressions. When you want to render them, you
can, for example, tessellate—that is, approximate them by sets of triangles—or simplify
them as your program proceeds. This mode of processing essentially substitutes CPU
cycles for limitations on the size of fast memory. The approach of the OpenGL Optimizer
toolkit is to treat a scene graph as a mutable object to be manipulated and altered
frequently; such calculations are essential to practical visualization of large CAD
datasets.
The basic OpenGL Optimizer elements are C++ classes that can be grouped roughly into
the general operations described this section, which contains the following subsections:
•
“Graphics Pipeline” on page 6
•
“Bottlenecks in the Pipeline” on page 7
•
“Tools to Optimize the Generate Stage” on page 8
•
“Tools to Optimize the Traversal Stage” on page 11
•
“Tools to Optimize the Transform Stage” on page 12
•
“Optimal Use of Rasterization Hardware” on page 15
The basic architectural modules, and their relations to lower-level software, are shown in
Figure 1-2.
5
Chapter 1: Overview of OpenGL Optimizer
he
e
rd
O
r-
ss
ne er
ar g
H na rs
P a e
M M rs cts
ph ve fe s
ra ra Ef er s
-G T g ull ier
in C if s
ne
ht
pl tor y
ce
ig
S
im a g
L
S ell olo es
ss op itiv
Te T im
r
P
ig
H
r
zer
i
ptim
O
GL
n
e
Op o 3D
sm
Co
GL ystem
n
e
Op ting S
era
Op
Figure 1-2
OpenGL Optimizer Architecture
Graphics Pipeline
You will more easily understand OpenGL Optimizer tools if you understand the generic
tasks of computer-generated graphics. These are the five fundamental stages in the
graphics pipeline, from host application to hardware display:
1.
Generate and organize data to be displayed. The organizational structure for
OpenGL Optimizer applications is a Cosmo3D scene-graph. If you use abstract
surfaces to define objects, you must tessellate them before further processing.
OpenGL Optimizer tools facilitate these tasks.
2. Traverse the data and produce graphics data. For OpenGL Optimizer applications,
this typically means generating OpenGL commands, often guided by
considerations of interobject occlusion and represenational priority.
OpenGL Optimizer and Cosmo3D scene graph tools share these tasks.
OpenGL tools perform the last three tasks:
6
How OpenGL Optimizer Helps
3. Transform object-description coordinates into an appropriate viewing context; for
example, apply lighting effects, perform perspective transformations, and
transform these data into screen-space primitives (points, lines, and polygons).
4. Rasterize screen-space primitives into a frame buffer. Perform per-vertex and
per-pixel operations such as texture lookups, shading calculations, and depth
testing.
5. Display the contents of the frame buffer, typically on a monitor screen.
For further discussion of the graphics pipeline, see section 6.5, “Hardware for OpenGL,”
and section 6.6, “Maximizing OpenGL Performance,” in Programming OpenGL for the X
Window System. OpenGL Optimizer implements many of the tuning suggestions
discussed in section 6.6. See also the OpenGL Programming Guide.
Bottlenecks in the Pipeline
Ideally, your graphics software uses the hardware at its full potential so that processing
is not slowed by a bottleneck at any stage and data flows through the stages of the
pipeline at a uniform rate. There are three broad types of rendering bottlenecks:
1.
Host: Generate- and traverse-stage limits are set by the efficiency of the software and
the performance of the CPU(s). The tasks of generating and organizing data for later
stages in the graphics pipeline, and scene graph traversal are CPU-intensive
operations.
2. Transform: Transform-stage limits are set by the rate at which the graphics hardware
(or software) can process vertices. For a single lighting source, the transformation
stage for one vertex takes approximately 100 floating-point operations.
3. Fill: Rasterize-stage limits are set by the rate at which the hardware can update the
frame buffer.
The term “host” refers to the first two stages of the graphics pipeline because OpenGL
defines a standard application program interface for the last three stages. Typical
machines running OpenGL Optimizer applications will have special-purpose graphics
hardware to implement the transform, rasterize, and display stages. In this manual, the
term “graphics hardware” is used to refer to only the OpenGL stages of the graphics
pipeline.
The nature of the graphics pipeline is such that rendering rate is controlled by the slowest
stage. Tuning a stage that is not a bottleneck will not affect performance. In fact, when
7
Chapter 1: Overview of OpenGL Optimizer
tuning an application, you might find that by adding processing to stages that are not
rate-controlling, you can improve the quality of images without affecting the rendering
rate.
The OpenGL Optimizer toolkit provides tools that typically minimize both host and
transform bottlenecks. In many cases the same tool will affect both a host bottleneck and
transform bottleneck. Typically large CAD applications are not fill limited.
Tools to Optimize the Generate Stage
OpenGL Optimizer provides the following tools:
8
•
A powerful multiprocess control “harness,” which can be used independently of
any graphics application. All aspects of OpenGL Optimizer are designed to work
with this MP harness.
•
Classes to facilitate multiprocess traversals of the scene graph with arbitrary
callbacks. These allow application speeds to scale with processor count.
•
A transaction manager that coordinates scene graph modifications by several
processes and maintain logical consistency in a complex, multiprocessor context.
How OpenGL Optimizer Helps
•
Higher-order geometric primitives, called reps, that you can include in the scene
graph. shows the set of reps included in OpenGL Optimizer. From left to right, the
following reps are shown:
Cuboid
Cylinder
Cone
Sphere
Torus
Ruled Surface
Swept Surface (here with a superquadric curve for cross section)
Coons Patch
Hermite Spline Surface
NURBS Surface
Figure 1-3
Higher-Order Surface Representations With Trimmed Pieces
9
Chapter 1: Overview of OpenGL Optimizer
Higher-order surfaces are required to accurately represent CAD data. Direct support
for them allows OpenGL Optimizer applications to handle large design databases
without sacrificing design integrity, an unavoidable sacrifice if only vertex-based
data is used. Direct support for higher-order surfaces also facilitates alteration of
surface shapes, as illustrated in Figure 1-4, which shows NURBS surfaces that differ
by moving two control points.
Figure 1-4
10
NURBS Surfaces Deformed From One Another by Moving Two Control Points
•
Tessellators for rendering higher-order geometric primitives. A tessellator in
OpenGL Optimizer is an independent object, not derived from a rep, that is applied
to a rep to produce a renderable object. The separation of tessellators from reps
allows your application to tessellate reps, and avoid storing large, renderable
objects. You can also apply one of several tessellators to a given rep, depending on
your need, or apply one tessellator to a set of reps.
•
Topology data structures to easily maintain continuity of adjacent higher-order
surfaces as you modify your model and stitch surfaces together, thus preventing the
appearance of cracks during tessellation.
How OpenGL Optimizer Helps
Tools to Optimize the Traversal Stage
OpenGL Optimizer provides tools that perform these tasks:
•
Organize a scene graph spatially, facilitating rapid culling operations and
interactions with the graph.
•
Restructure the scene graph for efficient highlighting and picking.
•
Subdivide large csGeoSets into smaller pieces defined by common rendering
features, such as proximity to each other or similarly oriented normal vectors.
•
Sort the scene graph to minimize attribute-specification overhed in the graphics
hardware.
•
Minimize the amount of data characterizing surface normals.
•
Reduce OpenGL command overhead.
•
Easily define arbitrary actions on a scene graph using the Visitor Behavioral Pattern
(see Design Patterns: Elements of Reusable Object-Oriented Software in “Recommended
Reference Materials” on page xxxi).
•
Maintain both a spatial view needed for rapid display, and, for example, a logical
structure defined by design concerns.
11
Chapter 1: Overview of OpenGL Optimizer
Tools to Optimize the Transform Stage
Cosmo3D provides level-of-detail scene graph nodes and view-frustum culling. The
OpenGL Optimizer library adds the following tools to further accelerate the transform
stage:
•
An occlusion culler to remove, before the transform stage, objects in the scene graph
that are occluded by closer objects. No preprocessing of the scene graph is required:
the culling is done automatically.
Figure 1-5 shows the exterior of a model containing many parts that have been
removed from the graphics pipeline by the occlusion culler. Only the shell needs to
be rendered; the culled geometry is shown in Figure 1-1.
Figure 1-5
12
Shell That Occludes the Objects Shown in Figure 1-1 (Data courtesy of SDRC™)
How OpenGL Optimizer Helps
•
Simplifiers to decimate the set of triangles that define a model image. OpenGL
Optimizer provides a new advanced simplification technology, known as the
Successive Relaxation Algorithm, which gives you control over high-quality
polygon mesh reduction. You can also use the faster, Rossignac simplification
algorithm if you are not greatly concerned about object distortion.
Figure 1-6 shows the effects of the Successive Relaxation Algorithm as the number
of triangles diminishes to nearly one tenth the original number. Essential structure
is preserved in the lowest resolution image, which is appropriate for use when the
object is viewed from greater distances.
Figure 1-6
•
Simplification From 4629 to 2002 to 483 Triangles
Mesh optimizers to reduce the number of vertices that need to be processed to
render a given set of triangles. You can remove redundant vertex information by
combining adjacent triangles into triangle strips (tristrips), triangle fans (trifans) or a
combination of both.
13
Chapter 1: Overview of OpenGL Optimizer
•
Tessellators that can approximate higher-order geometric primitives with adjustable
levels of detail.
Figure 1-7 shows tessellations of a swept surface at varying levels of detail. The
number of triangles used to approximate the surface decreases from 16,544, to 5,400,
to 528, to 120.
Figure 1-7
•
14
Tessellations of a Higher-Order Surface: 16,544 to 120 triangles
A scene-graph manipulation tool to insert level-of-detail nodes.
How OpenGL Optimizer Helps
Optimal Use of Rasterization Hardware
For design and styling, where image quality and interactivity is essential, OpenGL
Optimizer also provides advanced shading and reflection mapping capabilities.
Figure 1-8 and illustrate tube-lighting effects, which simulate florescent lights in a
cylindrical room and are computed at interactive rates with OpenGL Optimizer
advanced lighting tools. Unfortunately, some aliasing was introduced in transfer from
original screen images to the images shown.
Figure 1-8
TubeLighting: Note Differences of Lights on Hood and Roof Compared to
Figure 1-9 (Data courtesy of Alias|Wavefront™)
Figure 1-9
TubeLighting: Note Differences of Lights on Hood and Roof Compared to
Figure 1-8 (Data courtesy of Alias|Wavefront)
15
Chapter 2
2. Installing, Compiling, and Running
This chapter describes installingand compiling an OpenGL Optimizer application,
presents brief descriptions of sample applications, which are ready to compile and run,
and lists a minimal OpenGL Optimizer application.
These are the sections in this chapter:
•
“Installing the Library and Supporting Software” on page 17
•
“Environment Variables to Set Before Compiling an Application” on page 19
•
“Sample Applications” on page 20
•
“Running a Sample Application” on page 20
•
“Simple First Program” on page 24
Installing the Library and Supporting Software
The OpenGL Optimizer library can either be downloaded from the designated Web site
or from the release CD. In either case, use the Software Manager (swmgr) interface to
install the software.
17
Chapter 2: Installing, Compiling, and Running
In addition to the library, you need the software listed in Table 2-1, which also briefly
indicates why the software is needed and where to get it:
Table 2-1
Libaries Used by OpenGL Optimizer
Software Purpose
Program Name
Program Source
c++_dev
MIPSpro C++ 7.1 CD
c++_eoe
IRIX™ 6.2 part 1 of 2 or IRIX 6.3
CD
compiler_dev
7.1 IDO package. The IDO
package contains 3 CDs, one
per IRIX platform.
Compile programs in the developer build
environment.
dev
IRIS® Developer’s Option CD
Load Inventor™ files: Inventor 2.1.1 or
higher.
inventor_dev
and
inventor_eoe
IRIX 6.2 part 1 of 2 or IRIX 6.3
CD
To link with the Digital Media Execution
Environment.
dmedia_eoe
IRIX 6.2 part 1 of 2 or IRIX 6.3
CD
For reflection mapping: Image Format
Library.
ifl_eoe
Installable from Silcon SurfSM
as part of the ImageVision™
Runtimes 3.1.1
Compile and run C++ programs, use one of
the three.
The installation overwrites previously installed Cosmo3D and OpenGL Optimizer
libraries and sample applications. To avoid overwriting any changed files during the
installation, save them in another directory.
Sample OpenGL Optimizer applications, file loaders and scene-graph viewers are in
/usr/share/Optimizer/. Sample Cosmo3D applications are in /usr/share/Cosmo3D. Use the
commands make ddso or make dso to build these Cosmo3D programs.
18
Environment Variables to Set Before Compiling an Application
Environment Variables to Set Before Compiling an Application
Before compiling an OpenGL Optimizer application, you should set several environment
variables.
•
To specify which ABI to compile (o32, n32, or n64), enter this command:
setenv OBJECT_STYLE 32 or N32_M3 or 64
Note: For systems with IRIX 6.4, the compiler defaults to using n32. To force an o32
build enter this command:
setenv OBJECT_STYLE 32
•
To designate linking with single or double-precision OpenGL Optimizer libraries,
edit the ‘OP_DOUBLE’ value set in /usr/share/Optimizer/src/opusercommondefs .
•
To run-time load the debugging versions of the libraries, enter one of these
commands:
setenv LD_LIBRARY_PATH
/usr/lib/Optimizer/Debug:/usr/lib/Cosmo3D/Debug
setenv LD_LIBRARYN32_PATH
/usr/lib32/Optimizer/Debug:/usr/lib32/Cosmo3D/Debug
setenv LD_LIBRARY_PATH64
/usr/lib64/Optimizer/Debug:/usr/lib64/Cosmo3D/Debug
Note: For performance, do not set LD_LIBRARY_PATH to the
/usr/lib/{Optimizer,Cosmo3D}/Debug directories.
•
If you see a compile-time warning that mentions incompatible versions for libifl.so
(sgi1.0), and your application does not use reflection mapping, you can enter the
this command
setenv _RLD_ARGS -ignore_all_versions
This error occus if you have a more recent version of libifl.so that ships with IRIX 6.3
or 6.4: Image Vision Runtimes 3.1.1.
You can avoid the error message by installing the IRIX 6.2 libifl.so into a different
directory than /usr/lib and set your LD_LIBRARY_PATH to point to that directory
first. For example, if you install libifl.so in /usr/tmp/ifllib, enter the following
command:
setenv LD_LIBRARY_PATH /usr/tmp/ifllib:/usr/lib
For further details, see “Compiler Warning Messages” on page 377 and the file
/usr/share/Optimizer/doc/Programming_tips/Compile_Notes.html.
19
Chapter 2: Installing, Compiling, and Running
Sample Applications
To help you get started, the library includes applications designed to illustrate OpenGL
Optimizer applications and the power of the OpenGL Optimizer and Cosmo3D toolkits.
These applications are in individual subdirectories of the /usr/share/Optimizer/src/sample
directory.
This section describes how to run the applications, and briefly describes each application,
which you can compile and run when you have the OpenGL Optimizer library properly
installed.
Running a Sample Application
The sample applications all run similarly. To see the command-line options that are
available, invoke the executable without any arguments. To print a list of interactive
program controls into your command shell while you run a sample application (except
for viewXmdemo, which provides different interface), place the mouse cursor in the
rendering window and enter h.
The applications have many command-line arguments; for example, viewDemo and
optimizeDemo both have over 20. Optional arguments for demonstration applications
should be placed after any required arguments when you invoke a sample application.
For example, viewDemo and optimizeDemo requre only filename arguments, so
command lines could look like the following:
%viewDemo xxx.csb -useDL
%optimizeDemo xxx.csb -batch test.csb
viewDemo Application
This application illustrates the basic structure of a fully developed OpenGL Optimizer
application that includes most of OpenGL Optimizer’s rendering tools. It uses the
graphical user interface tools in /usr/share/Optimizer/src/libopGUI. The important tools in
this library, opViewer and opDefDrawImpl are discussed in Chapter 3, “Basic I/O
Tools: The Application viewDemo.”
A line-by-line commentary on viewDemo appears in Chapter 3 in the section
“Application viewDemo: A First Look in the Toolkit” on page 42.
20
Sample Applications
The command-line options for this program appear in the file
/usr/share/Optimizer/src/sample/viewDemo/main.cxx. Interactive control options are defined
by the class opDefDrawImpl, which is in the /usr/share/Optimizer/src/libopGUI directory
and is discussed in in Chapter 3 in “Default opDrawImpl for opViewer:
opDefDrawImpl” on page 40.
viewXmDemo Application
This application illustrates the use of OpenGL Optimizer in a Motif™ application. It
essentially duplicates the functionality of viewDemo, but relies on different graphical
user interface tools; /usr/share/Optimizer/src/libopXmGUI is the motif version of
/usr/share/Optimizer/src/libopGUI, which is used by viewDemo.
viewXmDemo is a typical Motif application that creates a main window and a menu bar.
The application also creates an opXmViewer widget attached to the main window.
opXmViewer is the motif version of opViewer, discussed in “Viewing Class: opViewer”
on page 33. opXmViewer is a composite Motif widget consisting of a main drawing area,
an information area (for help text), and a user interface area.
viewXmDemo takes the same command-line options as viewDemo, with the exception
of occlusion culling and no-picking options: occlusion culling is not available and the
picking option is always on. Interactive controls are defined by the class
opXmDrawImpl, which is the Motif analog to a combination of opDefDrawImpl and
opPickDrawImpl, which are discussed in “Basic Tools for Rendering Implementations:
opKeyCallback and opDrawImpl” on page 38; and in “Interaction With a Rendered
Object: opPickDrawImpl” on page 156.
As in viewDemo, translation, rotation and zoom are done in viewXmDemo using the
mouse in the drawing area. Unlike viewDemo, the other interactions are controlled by
buttons in the user interface area, rather than by keyboard commands. Passing the cursor
over a button causes the help text associated with that button to be displayed in the
information area.
xdemo Application
This application illustrates how to render a Cosmo3D scene graph inside of an
X Window™. It presents a minimal OpenGL Optimizer application and emphasizes the
process of rendering. It includes the necessary routines from the following libraries:
X Window, OpenGL extensions to X, Cosmo3D, and OpenGL Optimizer.
21
Chapter 2: Installing, Compiling, and Running
optimizeDemo Application
This application uses most of the OpenGL Optimizer scene-graph-tuning tools and is
mainly for batch processing, although it also allows you to view the scene graph using
an opViewer (see “Viewing Class: opViewer” on page 33).
A line-by-line commentary appears in Chapter 4, “Scene Graph Tuning With the
optimizeDemo Application.” This application adds to viewDemo the command-line
options and keyboard controls that appear in the file
/usr/share/Optimizer/src/sample/optimizeDemo/main.cxx.
mergeLODDemo
This application is a specialized application of the OpenGL Optimizer
scene-graph-tuning tools; it places level-of-detail (LOD) nodes at leaf nodes and
provides fewer options than optimizeDemo, which places LOD nodes near the root of the
scene graph.
The tool included in this application that does not appear in optimizeDemo is one that
allows you to combine topologically identical scene graphs that contain leaf nodes with
differing levels of detail. See “Merging Graphs With Differing Levels of Detail:
opMergeScenes” on page 119.
repTest Application
This application for rendering higher-order reps provides an environment where you
can try your hand developing and rendering these objects.
This application is discussed in Chapter 11, “Higher-Order Geometric Primitives and
Discrete Meshes.” It adds to viewDemo the command-line options that appear in the file
/usr/share/Optimizer/src/sample/reptest/main.cxx.
topoTest Application
This application illustrates the use of the OpenGL Optimizer topology building tools to
“stitch” together surfaces “by hand.” It is designed to help you import surfaces whose
connectivity you know so that you can use the OpenGL Optimizer tessellators to get
22
Sample Applications
crack-free images. The application also illustrates an approach to developing trimmed
NURBS surfaces that is a somewhat different from that used in repTest.
The topology building tools are discussed in Chapter 12, “Creating and Maintaining
Surface Topology.”
opviz Application
This application illustrates how to use OpenGL Optimizer to visualize discrete scientific
and engineering data.
This application is discussed in the section “Sample Mesh Tessellation: opviz and
opVizViewer” on page 306. It adds to viewDemo the command-line options that appear
in the file /usr/share/Optimizer/src/sample/opviz/main.cxx, and the interactive commands
that appear in opVizViewer.cxx.
zebraFly Application
This application illustrates the use of reflection mapping to get tube-lighting effects,
which simulate lighting by florescent lights in a cylindrical room. The file
/usr/share/Optimizer/src/sample/zebrafly/README describes the basic controls for the
application, which is based on viewDemo.
Reflection mapping tools are discussed in Chapter 10, “Efficient High-Quality Lighting
Effects: Reflection Mapping.”
23
Chapter 2: Installing, Compiling, and Running
Simple First Program
The following simple program initializes the OpenGL Optimizer library with a call to
opInit(); an opArgParser interprets command-line arguments; an opGenLoader loads
data files, which it can tessellate if necessary by using an opTessParaSurfaceAction; and
an opViewer controls interaction with the scene graph. These tools are discussed in more
detail in Chapter 3 and in Chapter 13, “Rendering Higher-Order Primitives:
Tessellators.” Note that the program allows you to load a model that is included in
several files.
Simple Program Code
#include
// you MUST include this file before csGroup.h
#include
#include
#include
#include
#include
#include
#include
#include
int main(int argc, char *argv[])
{
opInit();
opArgParser args;
char
*filename;
int
numFiles;
int
x=1280-600-10, y=0, w=600, h=600;
bool
haveChordalTol = -1;
opReal
chordalTol = 0.01; // 100th of meter if meters are the
// units of choice.
args.defRequired( “%s”,
“”,
&filename);
#ifdef OP_REAL_IS_DOUBLE
args.defOption( “-ctol %l”,
“-ctol ”,
24
Simple First Program
&haveChordalTol, &chordalTol );
#else
args.defOption( “-ctol %f”,
“-ctol ”,
&haveChordalTol, &chordalTol );
#endif
// Print out version of Optimizer
fprintf(stderr,”%s\n”,opVersion());
// Prepare to read filenames if more than one is supplied
numFiles = args.scanArgs(argc,argv);
// Create a tessellator
opTessParaSurfaceAction *tess;
tess = new opTessParaSurfaceAction;
// Set the chordal tolerance
tess->setChordalDevTol( chordalTol );
// Create a loader
opGenLoader *loader;
// Bind tessellator to loader so that
// tessellation is invoked at loading
loader = new opGenLoader( true, tess, false );
// Load the file on the command line and get a scene graph back
csGroup *obj = loader->load( filename );
if (numFiles)
{
// Loading more than one file
int i;
csGroup *grp = new csGroup;
if (obj)
{
grp->addChild(obj);
}
char **xtraFiles = args.getRemainingArgs();
for (i=0;iload(xtraFiles[i]);
if (obj)
{
grp->addChild(obj);
25
Chapter 2: Installing, Compiling, and Running
}
}
obj = grp;
}
// Throw the loader and tessellator away, we’re done with them
delete loader;
delete tess;
// If we got a scene graph draw it else end the program
if ( obj )
{
// Get stats on the scene graph
opTriStats stats;
stats.apply(obj);
printf(“Scene statistics:\n”);
stats.print();
opViewer *viewer = new opViewer(“Optimizer”, x, y, w, h);
viewer->addChild(obj);
viewer->setViewPoint(obj);
viewer->eventLoop();
}
}
26
Simple First Program
Compiling and Running the Simple Program
The easiest way to compile is to use one of the Makefiles in one of the
/usr/share/Optimizer/src/sample directories, and opusercommondefs shipped with the sample
code: copy and edit one of the sample Makefiles, then set the appropriate environment
variables: OPROOT, CSROOT, LD_LIBRARY_PATH, and OBJECT_STYLE. See
“Environment Variables to Set Before Compiling an Application” on page 19 and
/usr/share/Optimizer/doc/Programming_tips/Compile_Notes.html for more information.
Note: The Makefile in the inst image is looking for the opusercommondefs to be in a specific
location:
include $(OPROOT)/usr/share/Optimizer/src/opusercommondefs
To run the simple program, enter commands such as the following:
viewDemo datafile.csb
viewDemo datafile.iv
Supplying an Inventor (.iv) file causes the program to use the tessellator.
27
Chapter 3
3. Basic I/O Tools: The Application viewDemo
To get you started with OpenGL Optimizer applications and to provide basic program
I/O, the library includes opViewer, an interactive scene graph viewer that uses OpenGL
and Cosmo3D calls to render a scene, and the base class opDrawImpl, which allows you
to control the rendering options. Analogous tools that use Motif calls can be found in
/usr/share/Optimizer/src/libopXmGUI.
These are the sections in this chapter:
•
“Always First: Call opInit()” on page 29
•
“Reading and Writing Scene-Graph Files: The Extendable Loading Class
opGenLoader” on page 30
•
“Viewing Class: opViewer” on page 33
•
“Basic Tools for Rendering Implementations: opKeyCallback and opDrawImpl” on
page 38
•
“Application viewDemo: A First Look in the Toolkit” on page 42
Always First: Call opInit()
Every OpenGL Optimizer application must call opInit() once before calling any other
OpenGL Optimizer routine. You can terminate an OpenGL Optimizer application with a
call to opExit() or opNotify() (if the notification level is set to opFatal. See “Error
Handling and Notification” on page 366).
opInit provides the method opVersion(), which returns the OpenGL Optimizer version
string to use in correspondence concerning the specific OpenGL Optimizer library you
have installed. This string is defined by the following four definitions:
OP_MAJOR_VERSION
The major release number.
29
Chapter 3: Basic I/O Tools: The Application viewDemo
OP_MINOR_VERSION
The minor release number.
OP_RELEASE_TYPE
The type of release (apha, beta, MR, or unreleased).
OP_BUILD_VERSION
Build release number.
OP_BUILD_NUMBER
The unique build number.
Reading and Writing Scene-Graph Files: The Extendable Loading Class opGenLoader
The class opGenloader provides file-reading routines that create Cosmo3D scene graphs.
OpenGL Optimizer includes loaders for three file formats, and you can extend the class
to read any format.
The class provides loaders to read from the formats designated by the following file
extensions: .iv format, .csb, and .pfb. The .pfb, and .csb files are two highly efficient, binary
file formats used by OpenGL Optimizer and Cosmo3D.
•
The .iv files are the format used by Open Inventor.
•
The .pfb format allows you to interchange IRIS Performer readable data formats
with OpenGL Optimizer and Cosmo3D.
•
The .csb format is used by Cosmo3D to efficiently store and transfer scene graphs.
As you load the contens of a file, you can flatten the scene graph (see “Simplifying a
Scene Graph: opFlattenScene()” on page 98), tessellate higher-order primitives (see
Chapter 13, “Rendering Higher-Order Primitives: Tessellators”), or perform an
incremental load. When you flatten a scene graph, you get a structure where all leaf
nodes are under one csGroup node.
30
Reading and Writing Scene-Graph Files: The Extendable Loading Class opGenLoader
Saving a Scene Graph to a File
To write a scene graph to a .csb file, you can use one of the following:
•
Cosmo3D method csGlobal::storeFile()
•
Cosmo3D function csdStoreFile_csb() (link to the Cosmo3D library libcscsb)
The latter method is used in the demonstration application optimizeDemo.
File Format Conversions
The natural format for OpenGL Optimizer is the .csb format. You can use opGenLoader
to read a file, in particular an .iv file, and convert it to the .csb format by using one of the
Cosmo3D file storing tools.
Class Declaration for opGenLoader
The following are the main methods in the class:
class opGenLoader
{
public:
opGenLoader();
opGenLoader( const bool _flatten, opTessellateAction* _tesselator,
const bool incremental );
~opGenLoader();
csGroup *load( const char *filename );
void addType( const char *ext, const char *tag );
void
void
void
void
setDataFilePath( const char *path );
setFlatten( const bool _flatten ) ;
setTessellator( opTessellateAction *_tessellator );
setIncremental( const bool _incremental );
char *getDataFilePath( );
bool getFlatten( );
opTessellateAction *getTessellator( );
bool getIncremental( );
}
31
Chapter 3: Basic I/O Tools: The Application viewDemo
Main Features of the Methods in opGenLoader
opGenLoader(_ flatten, _tesselator, _incremental )
Sets logical flags indicating whether the loader should, flatten the scene
graph, tessellate geometric primitives on the fly, or incrementally read
the graph.
addType( ext, tag )
Adds a loader that reads files with the extension ext. The name of the dso
containing the loader is tagLoader_sp.so or tagLoader_dp.so, depending
on whether you compile in single or double precision. The variable tag
can include a pathname.
load()
Reads a data file, if it can find a DSO load routine.
setDataFilePath() and getDataFilePath()
Set the search paths for the DSO.
The class also includes accessor functions to set and get the flags for flattening and
incremental reads and to set and get the tessellator.
Adding a Scene Graph Loader
To develop your own scene graph loader, follow these steps:
1.
Associate the label tag with filename extension ext by calling addType().
2. Name the DSO containing the load function tagLoader_sp.so or tagLoader_dp.so,
depending on whether you compile single or double precision.
3. Name the load function within the DSO tagLoad() using standard C naming
conventions.
4. Declare the load function as follows:
csGroup* tagLoad(const char * filename, const bool flatten,
opTessellateAction* tessellator, const bool incremental)
See, for example, ivLoad() in ivLoader.cxx in the /usr/share/Optimizer/src/loaders/iv
directory. The ivLoader creates nearly every type of node available in Cosmo3D.
32
Viewing Class: opViewer
Viewing Class: opViewer
This class’s key operations are to add a data-model scene graph to a scene graph (as
shown in Figure 3-1) to facilitate interactions, and to register mouse and keyboard
controls for scene graph interaction. opViewer is designed to be extended by derivation.
Several features of the OpenGL Optimizer library were derived in this way, for example,
the class for scientific visualization, opVizViewer. The node opGLSpyNode,which
appears in Figure 3-1, is discussed in “Observing OpenGL Modes” on page 374.
To render using Motif library calls, see files in the directory
/usr/share/Optimizer/src/libopXmGUI. There you will find opXmViewer. The following
discussion should provide sufficient information to introduce you to the functionality of
that viewing class.
csGroup
root
csTransform
pose
model
graph
root
node
OpenGL
mode
watcher
csGroup
opGLSpyNode
Figure 3-1
opViewer Scene Graph
33
Chapter 3: Basic I/O Tools: The Application viewDemo
As for any OpenGL Optimizer application, an opViewer application begins by
initializing the library with a call to opInit(). Then the application need only instantiate
the viewer, load the scene graph, and call the event loop method. You can determine
interactions with the scene graph by setting drawing implementations (see “Basic Tools
for Rendering Implementations: opKeyCallback and opDrawImpl” on page 38). The
sample application viewDemo, discussed in “Application viewDemo: A First Look in the
Toolkit” on page 42, is an example of how to use an opViewer.
34
Viewing Class: opViewer
Class Declaration for opViewer
The following are the main methods in the class:
class opViewer
{
public:
// Creating and destroying
opViewer(const char *windowTitle=”unnamed”,
int x=0, int y=0, int w=512, int h=512,
int keyTableSize=512);
~opViewer();
// Accessor functions
csNode
*getScene() const;
csNode
*getRoot() const;
csLight
*getLight() const;
csLight
*getSecondLight() const;
csDrawAction *getDrawAction() const;
csContext
*getContext() const;
csCamera
*getCamera() const { return camera; }
int
getWidth() const;
int
getHeight() const;
void setViewPoint(csNode *n = NULL);
void setViewPoint(const csBoxBound &bbox, const csVec3f ¢er);
void
setReflMap( opReflMap *rm );
opReflMap *getReflMap();
// Utility methods
void setFarClip(float farVal);
void setNearClip(float nearVal);
void enableClipPlanes () { clipPlanesEnabled = true; }
void disableClipPlanes () { clipPlanesEnabled = false; }
void setBackgroundColor( float r, float g, float b, float a );
void getBackgroundColor( float *r, float *g, float *b, float *a );
void
setSaveImagePrefix( char *filename );
char
*getSaveImagePrefix();
void
setSaveImageSequenceNumber( int n );
int
getSaveImageSequenceNumber();
void
saveScreenImage();
void
setClipPlanes();
void addChild(csGroup *g);
void addImmobileChild(csNode *);
void replaceChild(csGroup *oldGrp, csGroup *newGrp);
35
Chapter 3: Basic I/O Tools: The Application viewDemo
void eventLoop(void);
// Functions dealing with opDrawImpl’s
void setDrawImpl(opDrawImpl *di);
opDrawImpl *getDrawImpl() const;
// Methods for mode control
void setBackFaceMode(
bool mode );
void setBoxBoundMode(
bool mode );
void setPickMode(
bool mode );
void setRotLightMode(
bool mode );
void setTwoLightMode(
bool mode );
void setLightsMode(
bool mode );
void setModelRotation( float x, float y, float z, float angle );
void setModelTranslation( float x, float y, float z );
void getModelRotation( float *x, float *y, float *z, float *angle );
void getModelTranslation( float *x, float *y, float *z );
void setStatsDisplayMode(
bool mode );
void setWireFrameMode(
bool mode );
void setScribeMode(
bool mode );
void setPreScribeLightMode( bool mode );
void setLODbias
(
int bias );
void
setStatsDisplayStyle(opStyle s);
bool getBackFaceMode() const;
bool getBoxBoundMode() const;
opGLSpyNode *getGLSpy() const;
bool getPickMode() const;
bool getRotLightMode() const;
bool getTwoLightMode() const;
bool getLightsMode() const;
bool getStatsDisplayMode() const;
bool getWireFrameMode() const;
bool getScribeMode() const;
bool getPreScribeLightMode() const;
int getLODbias() const;
opStyle getStatsDisplayStyle() const;
// Functions a user may call from an opDrawImpl
void clearWindow(void);
void drawScene(csNode *alt_root=NULL);
void drawStatistics(void);
void exit(int status=0);
void modelView(void);
void projection(void);
void printAppHelp(FILE *fp);
void printHelp(FILE *fp);
36
Viewing Class: opViewer
void reset();
void setMouseFocus (csTransform *new_pose);
void swapBuffers(void);
void update(void);
bool isSceneSpinning() const;
static int frameCallbackEntry(opViewer *);
};
Main Features of the Methods in opViewer
The names of the methods of opViewer are descriptive and often refer the OpenGL
Optimizer tools they control. Here are a few of the main methods:
addChild(g)
Adds group g as child of the pose transform, shown in Figure 3-1.
eventLoop()
Is the entry point for the X event loop for the window. eventLoop() starts
opViewer’s interactive mode. Perform all initializations of scene graph
data structures before calling eventLoop().
setDrawImpl() and getDrawImpl()
Set and get the opDrawImpl that currently controls scene graph
interactions. The constructor sets a default opDrawImpl, but you can
use others to allow, for example, highlighting and independent
manipulation of subgraphs (see Chapter 9, “Interactive Highlighting
and Manipulating”).
setLODbias() and getLODbias()
Set and get a bias for levels of detail when a scene is rotating.
A bias of i has the effect that, given a sequence of level-of-detail nodes
indexed by the integers 1 to n and arranged from highest to lowest level
of detail, after a level-of-detail calculation that would render node m,
the node m+i is rendered instead. This lightens the load on the graphics
hardware when you are not likely to need the most accurate object
representations.
setViewPoint()
Sets the view frustum to contain the bounding box of the graph rooted
at node passed as an argument. If the argument is NULL, the bounding
box of the entire scene graph is used.
The class opViewer contains many more methods; consult the man page and source code
for more details.
37
Chapter 3: Basic I/O Tools: The Application viewDemo
Basic Tools for Rendering Implementations: opKeyCallback and
opDrawImpl
opViewer uses objects derived from opDrawImpl to control rendering details and the
effects of specific keyboard controls.
opViewer uses a C++ array of functions to organize the effects of a set of keyboard
commands, which can come from several opDrawImpls (however, you cannot have
more than one opDrawImpl active at any given time). The array is an opKeyCallback,
which is the following pointer-to-function type:
typedef bool (*opKeyCallback)(opDrawImpl *drawImpl,int key);
Class Declaration for opDrawImpl
The following are the main methods in the class:
class opDrawImpl
{
public:
opDrawImpl(opViewer *viewer);
virtual ~opDrawImpl();
// Register keys and callbacks
void registerKey(int key, opKeyCallback keyCB,const char *helpMessage);
opViewer *getViewer() const;
// Callbacks
virtual void
virtual void
virtual void
virtual void
virtual void
};
38
to be implemented by the user.
draw(unsigned frame);
pick(bool mouseDown,const csHit& hit);
activated();
deactivated();
reset();
Viewing Class: opViewer
Main Features of the Methods in opDrawImpl
The methods of opDrawImpl do nothing. You create meaningful definitions in derived
classes. These are the intended uses of the member functions:
opDrawImpl(viewer)
Registers keys and their effects using the member function
registerKey().
registerKey(key, keyCB, helpmessage)
Registers a keyboard key and a callback function keyCB. keyCB becomes
a member of the opKeyCallback pointer-to-function array maintained
by the opViewer. keyCB interprets key in terms of the opDrawImpl’s
methods.
Each subclass defines at least one such member of opKeyCallback. The
subclasses of opDrawImpl in the OpenGL Optimizer library call this
defining function keyHandler() (see “Default opDrawImpl for
opViewer: opDefDrawImpl” on page 40, “Rendering With
View-Frustum and Occlusion Culling: opOccDrawImpl” on page 129,
and “Interaction With a Rendered Object: opPickDrawImpl” on
page 156).
Notice that different opDrawImpls cannot have different definitions
for one keyboard key. This allows you to include without ambiguity
several opDrawImpls in one opViewer and swtich among them. For
example you could select among the following opDrawImpls:
pick()
•
Default: see “Default opDrawImpl for opViewer: opDefDrawImpl”
on page 40
•
Picking: see “Interaction With a Rendered Object:
opPickDrawImpl” on page 156
•
Occlusion culling: see “Rendering With View-Frustum and
Occlusion Culling: opOccDrawImpl” on page 129
Allows you to define mouse interactions with a rendered object. See, for
example, the class opPickDrawImpl, which is discussed in “Interaction
With a Rendered Object: opPickDrawImpl” on page 156.
activated() and deactivated()
Define callbacks that are implemented when you switch to and from an
opDrawImpl using opViewer::setDrawImpl().
reset()
Returns a scene to the default settings defined by this function.
39
Chapter 3: Basic I/O Tools: The Application viewDemo
Default opDrawImpl for opViewer: opDefDrawImpl
This class defines the default drawing options and their keybinding for opViewer().
If you want to use the Motif library, opXmViewer uses opXmDrawImpl, which has
methods analogous to a combination of opDrawImpl and opPickDrawImpl. The latter
is an opDrawImpl that allows manipulation of selected objects in a scene. See
“Interaction With a Rendered Object: opPickDrawImpl” on page 156
Class Declaration for opDefDrawImpl
The class declaration is nearly identical to that of opDrawImpl. The main difference is
the inclusion of a member of the opKeyCallback function array called keyHandler(),
which defines the effects of keyboard commands. This is the prototype for the member
function keyHandler():
static bool keyHandler(opDrawImpl *,int);
Main Features of the Methods in opDefDrawImpl
40
keyHandler()
Defines the effects of the keyboard commands registered by calls to
registerKey(). opDefDrawImpl has the keyboard controls described in
“opDefDrawImpl Keybindings” on page 41.
registerKey()
Registers a keyboard command and specifies the function that interprets
the command. The function registerKey() is inherited from
opDrawImpl, which is discussed in “Basic Tools for Rendering
Implementations: opKeyCallback and opDrawImpl” on page 38. See the
file opDefDrawImpl.cxx for details.
Viewing Class: opViewer
opDefDrawImpl Keybindings
The class constructor for opDefDrawImpl uses the methods registerKey() and
keyHandler() to register the following keyboard commands (see the file
opDefDrawImpl.cxx):
b
Toggles back-face culling (see “Detail Culling” on page 135).
B
Toggles bounding-box display. Shows the csBoxBound of each
csGeoSet in the scene.
h
Prints help message listing these key actions.
q
Quits.
ESC
Quits.
r
Resets scene to what it was at the start of the application.
l
Toggles the light-direction mode, which allows you to control the
location of the light source with your mouse.
L
Toggles a second light source opposite the first.
p
Prints the scene graph.
s
Toggles status display.
t
Toggles reflection mapping illumination with the Gaussian map (see
Chapter 10, “Efficient High-Quality Lighting Effects: Reflection
Mapping”).
w
Toggles wire-frame mode, which shows the edges of the triangles that
define the objects in the scene.
W
Toggles hidden-line removal when in wire-frame mode.
SPACE
Stops scene motion.
?
Prints OpenGL status during the subsequent frame.
41
Chapter 3: Basic I/O Tools: The Application viewDemo
Application viewDemo: A First Look in the Toolkit
This application illustrates the basic structure of an OpenGL Optimizer opViewer
application that includes many of OpenGL Optimizer’s rendering tools. It is a working
application that allows you to use the rendering tools to manipulate complex models.
illustrates a model rendered by viewDemo.
Figure 3-2
A Model Rendered by the Application viewDemo
This section presents comments and lines of code essentially the same as that of
/usr/share/Optimizer/src/sample/viewDemo/main.cxx, briefly highlights OpenGL Optimizer
features, and refers to detailed discussions that appear in this guide. The code presented
here may not be exactly the same as the code that ships with OpenGL Optimizer, because
of late changes, but it should be close enough to orient you. The rest of this chapter is a
running commentary on the code in main.cxx.
42
Application viewDemo: A First Look in the Toolkit
These are the main tools omitted from viewDemo:
•
Explicit mention of tools for tuning the scene-graph database, which are discussed
in Part II, “High-Level Strategic Tools for Fast RenderingChapter 8”
•
Multiprocessing tools, which are discussed in Chapter 16, “Managing Multiple
Processors”
Analogous X Window and Motif Applications
If you are interested in developing a viewing application based directly on the X Window
library and OpenGL extensions to X, see the application xdemo in the
/usr/share/Optimizer/src/sample directory. The application xdemo does not use many of the
OpenGL Optimizer tools but emphasizes incorporating Cosmo3D rendering techniques
in an X window.
If you are interested in developing an application based on Motif, see viewXmDemo in
/usr/share/Optimizer/src/sample/viewXmDemo/main.cxx. This code is quite similar to
viewDemo.
Compiling and Running viewDemo
To compile viewDemo, enter the command make while in the directory
/usr/share/Optimizer/src/sample/viewDemo.
To run viewDemo, recall that command-line options are listed if you invoke the
application without any command-line arguments. To print a list of interactive program
controls into your command shell while you run viewDemo, place the mouse cursor in
the rendering window and enter h.
43
Chapter 3: Basic I/O Tools: The Application viewDemo
viewDemo Code
Inclusions
Besides the standard library, viewDemo requires
two base clases from the Cosmo3D library, and
header files from OpenGL Optimizer that provide
classes that provide the following features.
#include
You can set all csAppearances of the csShapes to
minimize mode switching. See “Avoiding OpenGL
Mode Switching” on page 96.
#include
These two headers include the OpenGL Optimizer
command-line argument parser, which is discussed
in the section “Command-Line Parser:
opArgParser” on page 375; and the file loading
class, discussed in “Reading and Writing
Scene-Graph Files: The Extendable Loading Class
opGenLoader” on page 30.
#include
This header includes the basic graphics acceleration
tools, most of which are discussed in Chapter 5,
“Sending Efficient Graphics Data to the Hardware.”
#include
The library initialization class is discussed in
“Always First: Call opInit()” on page 29.
#include
The basic control of interactive rendering, including
the control of occlusion culling or the ability to
manipulate selected portions of the scene graph is
provided by the classes in these files.These tools are
discussed in “Rendering With View-Frustum and
Occlusion Culling: opOccDrawImpl” on page 129,
and “Interaction With a Rendered Object:
opPickDrawImpl” on page 156.
#include
OpenGL Optimizer provides several tools for
reflection mapping, discussed in Chapter 10,
“Efficient High-Quality Lighting Effects: Reflection
Mapping.”
#include
44
#include
#include
#include
#include
Application viewDemo: A First Look in the Toolkit
Inclusions (cont.)
Traversal tools are discussed in Chapter 14,
“Traversing a Large Scene Graph.”
#include
You can collect statistics about the numbers of
vertices, triangles, and connected primitives in your
scene graph. See “Gathering Triangle Statistics” on
page 369.
#include
The next file holds the basic rendering class
opViewer, discussed in “Viewing Class: opViewer”
on page 33.
#include
Initializations and main()
The tessellators convert abstract geometries into
renderable collections of vertices: see “Tessellating
Parametric Surfaces” on page 295.
#include
To guarantee consistent tessellations between
adjacent surfaces, that is rendered surfaces without
cracks, OpenGL Optimizer provides topology
maintenance tools. See Chapter 12, “Creating and
Maintaining Surface Topology.”
#include
You have three ways to develop surface connectivity
information. The values enumerated list from best
to worst. See Chapter 12, “Creating and
Maintaining Surface Topology.”
enum topologyOption {TOPO_TWO_PASS,
TOPO_ONE_PASS, TOPO_NO};
#include
int main(int argc, char *argv[])
{
See “Always First: Call opInit()” on page 29.
opInit();
Command-Line Control Parameters
The command-line control parameters are read
using the methods in the class opArgParser (see
“Command-Line Parser: opArgParser” on
page 375). The command-line parameters set
switches that allow you to control these features:
opArgParser args;
char
*filename;
45
Chapter 3: Basic I/O Tools: The Application viewDemo
Command-Line Control Parameters (cont.)
The location on the screen (x, y) of the rendering
window, and the dimensions of the window (w,h).
The x-coordinate assumes a screen of width 1280,
and a rendering window of width 600 with a
10-pixel boundary.
bool
int
haveX=-1, haveY=-1, haveW=-1,
haveH=-1, haveSize=-1;
x=1280-600-10, y=0, w=600, h=600;
OpenGL display lists. See “Display Lists” on
page 94.
bool
haveDL;
bool
int
haveFrameCount;
frames = 0;
Print the scene graph. See “Viewing a Scene Graph”
on page 368.
bool
havePrint;
Flatten the scene graph, that is, placing all leaf nodes
directly under one group node. See “Main Features
of the Methods in opCollapseAppearance” on
page 97.
bool
haveFlatten;
Use short representations of surface normal data.
See “Vertex Arrays” on page 95.
bool
haveShortNorms;
Introduce complex lighting effects with reflection
(or environment) maps. See Chapter 10, “Efficient
High-Quality Lighting Effects: Reflection
Mapping.”
bool
char
bool
char
bool
bool
int
Set a bias for level-of-detail calculations when the
scene is moving. This feature of opViewer is
discussed in “Viewing Class: opViewer” on page 33.
bool
int
haveLODbias;
lodBias;
Specify the hint for maximum deviations of a
tessellation from the exact surface representation.
See “Tessellating Parametric Surfaces” on page 295.
bool
opReal
haveChordalTol = -1;
chordalTol = 0.01;
Specify the threshhold distance between points
below which they are considered identical when
building topology. See “Summary of Scene Graph
Topology: opTopo” on page 270.
bool
opReal
haveTopoTol;
topoTol;
46
haveReflMap;
*reflMapFilename;
haveCeilingMap;
*ceilingMapFilename;
haveCylinderMap;
haveGaussianMap;
numFiles;
Application viewDemo: A First Look in the Toolkit
Command-Line Control Parameters (cont.)
Specify the background color for the rendering
window and the model orientation. These settings
are controlled by opViewer options. See “Viewing
Class: opViewer” on page 33.
bool haveBackgroundColor;
float backgroundRed, backgroundGreen,
backgroundBlue, backgroundAlpha;
bool
float
haveRotation;
vx, vy, vz, angle;
bool
float
haveTranslation;
tx, ty, tz;
Specify the number of vertices in the tessellation of
surface boundaries. See “opTessParaSurfaceAction”
on page 295.
bool
int
haveSamples;
samples;
Specify the type of tessellator: a generic parametric
surface tessellator or a NURBS surface tessellator.
See “Tessellating Parametric Surfaces” on page 295.
bool
char
Specify rendering features: occlusion culling (see
“Occlusion Culling” on page 126) or interactive
manipulation (see Chapter 9, “Interactive
Highlighting and Manipulating”).
// --- Draw impl options
bool
haveOccCull;
int
nProcs = 2;
bool
haveNoPick = false;
bool
removeColors;
Play back a tour of the scene. See “Rendering With
View-Frustum and Occlusion Culling:
opOccDrawImpl” on page 129
// Option to playback recordings
bool
havePath;
char
*pathFile;
bool
haveAutoPlay;
Control OpenGL mode switching by clamping the
first csAppearance encountered in the draw
traversal to all subsequent csShapes. See “Avoiding
OpenGL Mode Switching” on page 96.
bool
By default, build the best topology. See Chapter 12,
“Creating and Maintaining Surface Topology.”
bool
haveTessType = -1;
*tessType = NULL;
haveOneAppearance;
isOnePass = false;
47
Chapter 3: Basic I/O Tools: The Application viewDemo
Get Command-Line Parameters
You must supply a file with the scene graph. All
other command-line control parameters are
optional and were described with the argument
declarations. See “Command-Line Parser:
opArgParser” on page 375.
args.defRequired( “%s”,
“”,&filename);
args.defOption( “-width %d”,
“-width ”,
&haveW, &w );
args.defOption( “-height %d”,
“-height ”,
&haveH, &h );
args.defOption( “-size %d”,
“-size ”,
&haveSize, &w );
args.defOption( “-xpos %d”,
“-xpos ”,
&haveX, &x );
args.defOption( “-ypos %d”,
“-ypos ”,
&haveY, &y );
args.defOption( “-useDL”,
“-useDL”,
&haveDL );
args.defOption( “-frames %d”,
“-frames ”,
&haveFrameCount, &frames );
args.defOption( “-print”,
“-print”,
&havePrint );
args.defOption( “-flatten”,
“-flatten”,
&haveFlatten );
48
Application viewDemo: A First Look in the Toolkit
Get Command-Line Parameters (cont.)
args.defOption( “-shortNorms”,
“-shortNorms”,
&haveShortNorms );
args.defOption( “-reflmap %s”,
“-reflmap ”,
&haveReflMap,
&reflMapFilename );
args.defOption( “-ceilingmap %s”,
“-ceilingmap”,
&haveCeilingMap, &ceilingMapFilename );
args.defOption( “-cylindermap”,
“-cylindermap”,
&haveCylinderMap );
args.defOption( “-gaussianmap”,
“-gaussianmap”,
&haveGaussianMap );
args.defOption( “-occ %d”,
“-occ ”,
&haveOccCull,
&nProcs);
args.defOption( “-nopick”,
“-nopick”,
&haveNoPick);
args.defOption( “-lodBias %d”,
“-lodBias ”,
&haveLODbias,
&lodBias );
args.defOption( “-noColors”,
“-noColors removes color bindings from
csGeoSets”,
&removeColors);
args.defOption( “-path %s”,
“-path ”,
&havePath,
&pathFile );
49
Chapter 3: Basic I/O Tools: The Application viewDemo
Get Command-Line Parameters (cont.)
args.defOption( “-autoplay”,
“-autoplay”,
&haveAutoPlay);
#ifdef OP_REAL_IS_DOUBLE
args.defOption( “-ctol %l”,
“-ctol ”,
&haveChordalTol, &chordalTol );
args.defOption( “-ttol %l”,
“-ttol [setting ttol
implies automatic topology building]”,
&haveTopoTol, &topoTol );
#else
args.defOption( “-ctol %f”,
“-ctol ”,
&haveChordalTol, &chordalTol );
args.defOption( “-ttol %f”,
“-ttol [asetting ttol
implies automatic topology building]”,
&haveTopoTol, &topoTol );
#endif
args.defOption( “-onePass”,
“-onePass [build topology while tessellating]”,
&isOnePass );
args.defOption( “-oneAppearance”,
“-oneAppearance”,
&haveOneAppearance );
args.defOption( “-ceilingmap %s”,
“-ceilingmap”,
&haveCeilingMap, &ceilingMapFilename );
args.defOption( “-tess %s”,
“-tess ”,
&haveTessType,
&tessType );
50
Application viewDemo: A First Look in the Toolkit
Get Command-Line Parameters (cont.)
// User defined background color
args.defOption( “-background %f %f %f %f”,
“-background ”,
&haveBackgroundColor,
&backgroundRed,
&backgroundGreen,
&backgroundBlue,
&backgroundAlpha );
// User defined model orientation
args.defOption( “-rotation %f %f %f %f”,
“-rotation ”,
&haveRotation, &vx, &vy, &vz, &angle );
args.defOption( “-translation %f %f %f”,
“-translation ”,
&haveTranslation, &tx, &ty, &tz );
args.defOption( “-samples %d”,
“-samples ”,
&haveSamples,
&samples);
51
Chapter 3: Basic I/O Tools: The Application viewDemo
Establish Status Information
// Print out version of Optimizer
fprintf(stderr,”%s\n”,opVersion());
//set topoOption
topologyOption topoOption;
if (!haveTopoTol)
{
topoOption = TOPO_NO;
//don’t build topology
}
else if (isOnePass)
{
topoOption = TOPO_ONE_PASS;
//build topology while tessellating.
}
else
{
topoOption = TOPO_TWO_PASS;
//build topology in a seperate pass before
//tessellation
}
numFiles = args.scanArgs(argc,argv);
if (haveSize)h = w;
52
Application viewDemo: A First Look in the Toolkit
Create the Appropriate Tessellator
See Chapter 13, “Rendering Higher-Order
Primitives: Tessellators.”
// Create a tessellator
opTessParaSurfaceAction *tess;
if (
tess
else
tess
else
tess
else
tess
tessType == NULL )
= new opTessParaSurfaceAction;
if ( strcmp( tessType, “gen” ) == 0 )
= new opTessParaSurfaceAction;
if ( strcmp( tessType, “nurb” ) == 0 )
= new opTessNurbSurfaceAction;
= new opTessParaSurfaceAction;
// Set the chordal tolerance
tess->setChordalDevTol( chordalTol );
// Set the sample count if the user set them
if ( haveSamples )
tess->setSampling( samples );
Create the Topology Data Structures
See Chapter 12, “Creating and Maintaining Surface
Topology.”
//topology
opTopo *topo = new opTopo;
// Set the topology parameters
if ( haveTopoTol )
{
topo->setDistanceTol( topoTol, meter );
}
53
Chapter 3: Basic I/O Tools: The Application viewDemo
Load the Scene Graph Data
The loader manages topology in one of the
following ways:
• It anticipates the development of connectivity
information for all surfaces in the scene graph
followed by tessellating the surface. Code for these
steps appears later in the application.
• It develops connectivity information as surfaces
load, and tessellates them.
• It ignores connectivity: it simply tessellates
surfaces as they load without regard for adjacencies.
See “Reading and Writing Scene-Graph Files: The
Extendable Loading Class opGenLoader” on
page 30; Chapter 12, “Creating and Maintaining
Surface Topology”; and “Base Class
opTessellateAction” on page 289.
// Create a loader
opGenLoader *loader;
if(topoOption == TOPO_TWO_PASS)
//build topology before tessellating any
//surface.
{
loader = new opGenLoader( true, NULL, false );
//the tessellator is not bound to the loader so
//that there is no tessellation at loading. The
//reason is because tessellation has to wait
//until topology construction is completely done
//for all the surfaces
}
else if( topoOption == TOPO_ONE_PASS )
//build topology while tessellate
{
tess->setBuildTopoWhileTess(true);
//tell the tessellator to invoke topology
//construction at tessellation
tess->setTopo(topo);
//Sets the topology which will be used in the
//topology building tessellation.
loader = new opGenLoader( true, tess, false );
//bind tessellator to loader so that
//tessellation is invoked at loading
}
else //don’t build topology
{
//bind tessellator to loader so that
//tessellation is invoked at loading
loader = new opGenLoader( true, tess, false );
}
// Load the file on the command line and get a
// scene graph back
csGroup *obj = loader->load( filename );
54
Application viewDemo: A First Look in the Toolkit
Load the Scene Graph Data (cont.)
If there are several files making up the scene graph,
place them under a csGroup node.
if (numFiles)
{
int i;
csGroup *grp = new csGroup;
if (obj)
{
grp->addChild(obj);
}
char **xtraFiles =
args.getRemainingArgs();
for (i=0;iload(xtraFiles[i]);
if (obj)
{
grp->addChild(obj);
}
}
obj = grp;
}
// Throw the loader away, we’re done with it
delete loader;
Build Topology and Tessellate
The most accurate topology, which yields crack-free
tessellations, is created by two traversals of the
scene graph: one to establish adjacencies of surfaces,
and the second to tessellate the surfaces. See
“Building Topology: Computing and Using
Connectivity Information” on page 273.
// Build topology if we haven’t done it and the
// user asks for it
if ( obj && topoOption == TOPO_TWO_PASS)
{
fprintf(stderr, “Building topology starts ...
\n”);
topo->buildTopologyTraverse( );
fprintf(stderr, “Building topology done\n”);
fprintf(stderr, “Tessellation starts ... \n”);
tess->apply( obj );
fprintf(stderr, “Tessellation done ... \n”);
}
delete tess;
55
Chapter 3: Basic I/O Tools: The Application viewDemo
Set Parameters to Draw the Scene
// If we got a scene graph draw it else end the
program
if ( obj )
{
See “Gathering Triangle Statistics” on page 369.
// Get stats on the scene graph
opTriStats stats;
stats.apply(obj);
printf(“Scene statistics:\n”);
stats.print();
See “Avoiding OpenGL Mode Switching” on
page 96.
if (haveOneAppearance)
{
opCollapseAppearances c;
c.apply(obj);
}
if (removeColors)
opRemoveColorBindings(obj);
See “Main Features of the Methods in
opCollapseAppearance” on page 97.
// Optionally flatten the scene graph
if (haveFlatten)
obj = opFlattenScene(obj);
See “Vertex Arrays” on page 95.
if (haveShortNorms)
opShortNormsScene(obj);
See “Viewing Class: opViewer” on page 33.
// Note: viewer must be created before
// opDListScene.
opViewer *viewer =
new opViewer(“Optimizer”, x, y, w, h);
Set the background color. See “Viewing Class:
opViewer” on page 33.
if ( haveBackgroundColor )
{
viewer->setBackgroundColor( backgroundRed,
backgroundGreen, backgroundBlue,
backgroundAlpha );
}
Set the bias for LOD calculations color. See
“Viewing Class: opViewer” on page 33.
// Set the LOD bias
if (haveLODbias)
{
viewer->setLODbias( lodBias );
}
56
Application viewDemo: A First Look in the Toolkit
Set Parameters to Draw the Scene (cont.)
See “Basic Tools for Rendering Implementations:
opKeyCallback and opDrawImpl” on page 38;
“Rendering With View-Frustum and Occlusion
Culling: opOccDrawImpl” on page 129; and
“Interaction With a Rendered Object:
opPickDrawImpl” on page 156.
// Make Occ draw object the default.
opOccDrawImpl *occDrawImpl = NULL;
if (haveOccCull || havePath)
{
occDrawImpl = new opOccDrawImpl(viewer,nProcs);
viewer->setDrawImpl(occDrawImpl);
if (havePath)
occDrawImpl->loadRecording(pathFile);
}
opPickDrawImpl *pi = NULL;
if (! haveNoPick) // bad grammar, i know
{
pi = new opPickDrawImpl(viewer);
// Use default DrawImpl until pick invoked
}
See “Viewing a Scene Graph” on page 368
if (havePrint) opPrintScene(obj);
See “Viewing Class: opViewer” on page 9.
viewer->addChild(obj);
viewer->setViewPoint(obj);
57
Chapter 3: Basic I/O Tools: The Application viewDemo
Set Parameters to Draw the Scene (cont.)
See Chapter 10, “Efficient High-Quality Lighting
Effects: Reflection Mapping.”
// A new reflection map
opReflMap *rm = NULL;
if ( haveReflMap )
{
rm = new opReflMap( obj, reflMapFilename,
opReflMap::SPHERE );
}
else if ( haveGaussianMap )
{
rm = new opReflMap( obj, (char *)NULL,
opReflMap::GAUSSIAN | opReflMap::SPHERE );
}
else if ( haveCylinderMap )
{
rm = new opReflMap( obj, (char *)NULL,
opReflMap::CYLINDER );
}
else if ( haveCeilingMap )
{
rm = new opReflMap( obj, ceilingMapFilename,
opReflMap::CEILING );
}
viewer->setReflMap( rm );
// --- picker needs refl map for highlighting //
(could be passed into constructor also)
if (pi != NULL)
pi->setReflMap( rm );
See “Display Lists” on page 94.
58
// Build display lists
// Note: this must be done after
// instantiating opReflMap and any
// other csGeometry changes.
if (haveDL)
{
printf(“Display listing scene.\n”);
opDListScene(obj);
}
Application viewDemo: A First Look in the Toolkit
Set Parameters to Draw the Scene (cont.)
Set orientation of model, if specified. See “Viewing
Class: opViewer” on page 33.
if ( haveRotation )
{
viewer->setModelRotation( vx, vy, vz, angle );
}
if ( haveTranslation )
{
viewer->setModelTranslation( tx, ty, tz );
}
Draw the Scene
if (haveFrameCount)
for (int i=0;iupdate();
else if (haveAutoPlay && havePath)
occDrawImpl->playback(true);
else
viewer->eventLoop();
}
}
59
Chapter 4
4. Scene Graph Tuning With the optimizeDemo
Application
The application optimizeDemo illustrates the basic structure of a scene-graph tuning
application. Scene-graph tuning is typically done before you begin rendering the model
for design work, so the main use of optimizeDemo is for batch processing. However,
optimizeDemo does allow scene-graph rendering interactions using an opViewer (see
“Viewing Class: opViewer” on page 33). The output of the application is typically a scene
graph that can be easily manipulated in an application like viewDemo, which was
discussed in Chapter 3.
This chapter presents lines of code that are essentially the same as those of
/usr/share/Optimizer/src/sample/optimizeDemo/main.cxx. Comments briefly highlight
OpenGL Optimizer features when they are referred to in the code, and direct you to
detailed discussions that appear in this guide. The code presented here may not be
exactly the same as what ships with OpenGL Optimizer, because of late changes, but it
is close and serves the purpose of presenting features of the OpenGL Optimizer toolkit.
The main tools not included in optimizeDemo are tools for multiprocessing, which are
discussed in Chapter 16, “Managing Multiple Processors.”
61
Chapter 4: Scene Graph Tuning With the optimizeDemo Application
General Features of Values Returned by Scene Graph Tools
As a general principle when you use OpenGL Optimizer methods that construct scene
graphs and csGeoSets, don’t use input pointers after the method call; the input objects
may change as a result of applying the method or they may be included in the output.
This may occur, for example, with the simplifiers, tessellators, and spatialization tools.
The problem that can arise if an input object is included in the output is that subsequent
changes to the original input may affect the output object. For example, if you generate
a level of detail node by simplifying a csGeoSet and you want color to distinguish the
levels of detail, but the simplifier could not change the input because of the criteria you
used, then a color change applied to input will also change the color of the output.
If you want to use an input scene graph or csGeoSet after a call to any modifying
method, make a copy first.
Compiling and Running optimizeDemo
To compile optimizeDemo, enter the command make while in the directory
/usr/share/Optimizer/src/sample/optimizeDemo.
To run optimizeDemo, recall that command-line options are listed if you invoke the
application without any command-line arguments. To print a list of interactive program
controls into your command shell while you run optimizeDemo, place the mouse cursor
in the rendering window and enter h.
Figure 4-1 illustrates using optimizeDemo to simplify a tessellation from 4629 to 2002 to
483 triangles. The three panels in the figure correspond, from left to right, to the
following three commands:
optimizeDemo aircar.iv -background 1 1 1 1 -rotation 0.190327 0.971742 0. 139621 1.866740
-translation -0.015904 -0.026498 -4.610418
optimizeDemo aircar.iv -background 1 1 1 1 -rotation 0.190327 0.971742 0.139621 1.866740
-translation -0.015904 -0.026498 -4.610418 -simpPercent 30. 10. -simplify -tristrip
optimizeDemo aircar.iv -background 1 1 1 1 -rotation 0.190327 0.971742 0.139621 1.866740
-translation -0.015904 -0.026498 -4.610418 -simpPercent 5. 100. -simplify -tristrip
62
Compiling and Running optimizeDemo
The first command renders the model on a white background with a specific orientation.
The second command simplifies the model, as controlled by the -simpPercent 30. 10.
-simplify command-line options; and the third command simplifies the model further.
The simplifier used for these images is discussed in “Main Features of the Methods in
opSimplify:” on page 114.
In each case when the model was rendered, w was entered to yield the wire-frame views.
Figure 4-1
Simplifying a Model With optimizeDemo
The rest of this chapter is a running commentary on the code in main.cxx.
63
Chapter 4: Scene Graph Tuning With the optimizeDemo Application
optimizeDemo Code
Note: The sequence in which tools are applied to the scene graph in optimizeDemo is
not fundamental to a scene-graph tuning application; if you use optimizeDemo as a
template, other orderings may be more appropriate for your needs.
Inclusions
These headers include the necessary objects from
Cosmo3D.
#include
See “Command-Line Parser: opArgParser” on
page 375.
#include
You can simplify the rendering task by culling
small features from the scene. See “Detail Culling”
on page 135.
#include
See “Reading and Writing Scene-Graph Files: The
Extendable Loading Class opGenLoader” on
page 30.
#include
This header provides various functions that
control specific features of the scene graph and
accelerate rendering. For example, see “Display
Lists” on page 94, “Vertex Arrays” on page 95,
and “Main Features of the Methods in
opCollapseAppearance” on page 97.
#include
See “Always First: Call opInit()” on page 29.
#include
See “Error Handling and Notification” on
page 366.
#include
64
#include
#include
#include
#include
#include
#include
#include
optimizeDemo Code
Inclusions (cont.)
The basic control of interactive rendering,
including keyboard commands and the ability to
manipulate selected portions of the scene graph,
are provided by the classes in these files. See
“Default opDrawImpl for opViewer:
opDefDrawImpl” on page 40 and “Interaction
With a Rendered Object: opPickDrawImpl” on
page 156.
#include
#include
To make scene graph traversals more efficient, you
can organize nodes spatially. See Chapter 8,
“Organizing the Scene Graph Spatially.”
#include
A sophisticated simplification tool is provided by
this file. See “Main Features of the Methods in
opSimplify:” on page 114.
#include
You can collect statistics about the numbers of
vertices, triangles and connected primitives in
your scene graph. See “Gathering Triangle
Statistics” on page 369.
#include
Includes classes to develop connected primitives
from a set of triangles in a csGeoSet. See “Merging
Triangles Into Both Strips and Fans:
opTriFanAndStrip” on page 107 and “Merging
Triangles Using Multiple Processors:
opMPTriFanAndStrip” on page 109.
#include
This file holds the basic rendering class opViewer,
discussed in “Viewing Class: opViewer” on
page 33.
#include
#include
65
Chapter 4: Scene Graph Tuning With the optimizeDemo Application
Inclusions (cont.)
Tessellators convert abstract geometries into
renderable collections of triangles. See
“Tessellating Parametric Surfaces” on page 295.
This application focuses mainly on simplifying
the rendering task by using tessellations with
differing levels of resolution, by removing
triangles from tessellated objects, and by
reorganizing the distribution of triangles in the
scene graph.
#include
To guarantee consistent tessellations between
adjacent surfaces, that is, surfaces rendered
without cracks, OpenGL Optimizer provides
topology maintenance tools. See Chapter 12,
“Creating and Maintaining Surface Topology.”
#include
These files are in the optimizeDemo directory.
#include
#include
#include
#include
#include
#include
“colorTag.h”
“deleteSurf.h”
“removeEmpty.h”
“simplify.h”
“convert.h”
Initialize
You can use either of the algorithms to remove
triangles from a mesh. See “Successive Relaxation
Algorithm: opSRASimplify” on page 115 and
“Rossignac Simplification Algorithm:
opLatticeSimplify” on page 118.
Here the application initializes the control
parameter for one of the simplification tools and
creates an instance of the other.
// Global simplifier paramaters for passing to
// app-defined key bindings
You have three ways to develop surface
connectivity information. The values enumerated
list from best to worst. See Chapter 12, “Creating
and Maintaining Surface Topology.”
int LODoffset;
66
float gridSpacing = 0.08;
opSRASimplifier simplfier;
enum opTopoOption
{TOPO_TWO_PASS, TOPO_ONE_PASS, TOPO_NO};
optimizeDemo Code
Define a Key Handler
The key handler extends the default keyboard
controls available during rendering. See “Default
opDrawImpl for opViewer: opDefDrawImpl” on
page 40.
//
//
//
//
//
//
//
SimplifyViewer extends opViewer by adding new
key bindings:
‘g’ : (go) simplify the scene graph
‘c’ : (go) tristrip the scene graph w/ random
colors
‘C’ : (go) tristrip the scene graph w/o random
colors
static bool keyHandler(opDrawImpl *di, int key)
{ opViewer *viewer = di->getViewer();
bool retVal = true;
switch(key)
{
See “Merging Triangles Into Strips: opTriStripper”
on page 105; and “Gathering Triangle Statistics”
on page 369.
case ‘c’:
case ‘C’:
// Show different colored tristrips
triStripTree( (csGroup *)viewer->getRoot(),
(key==’c’)?true:false);
{
opTriStats ts(8);
ts.apply(viewer->getRoot());
ts.print();
}
retVal = false;
break;
67
Chapter 4: Scene Graph Tuning With the optimizeDemo Application
Define a Key Handler (cont.)
See the file simplify.h and “Rossignac
Simplification Algorithm: opLatticeSimplify” on
page 118, and “Gathering Triangle Statistics” on
page 369.
case ‘G’:
opNotify(opInfo,opNull,
”Invoking Rossignac simplifier with gridSpacing =
%2.3f\n”,gridSpacing);
latticeSimplifySameTree(
(csGroup *)viewer->getRoot(), gridSpacing);
gridSpacing *= 2.0;
{
opTriStats ts(14);
ts.apply(viewer->getRoot());
ts.print();
}
break;
See the file simplify.h and “Successive Relaxation
Algorithm: opSRASimplify” on page 115, and
“Gathering Triangle Statistics” on page 369.
case ‘g’:
opNotify(opInfo,opNull,
”Invoking SRA simplifier.”);
simplifySameTree(
(csGroup *)viewer->getRoot(), &simplfier);
{
opTriStats ts(14);
ts.apply(viewer->getRoot());
ts.print();
}
retVal = false;
break;
The LOD offset adjusts the LOD calculation when
objects in the scene are moving. See “Viewing
Class: opViewer” on page 33.
case ‘+’:
changeLODOffset(
(csGroup *)viewer->getRoot(),++LODoffset);
retVal = false;
break;
case ‘-’:
changeLODOffset(
(csGroup *)viewer->getRoot(),--LODoffset);
retVal = false;
break;
68
optimizeDemo Code
Define a Key Handler (cont.)
This calls a Cosmo3D function to save a scene
graph to a file in .csb format. See “Reading and
Writing Scene-Graph Files: The Extendable
Loading Class opGenLoader” on page 30.
case ‘z’:
csdStoreFile_csb(
(csGroup *)viewer->getRoot(),”test.csb”);
break;
default:
break;
}
return retVal;
main()
See “Always First: Call opInit()” on page 29 and
“Command-Line Parser: opArgParser” on
page 375.
int main(int argc, char *argv[])
{
opInit();
opArgParser args;
int numFiles;
char *filename,*outFile;
Command-Line Control Parameters
The location on the screen (x, y) of the rendering
window, and the dimensions of the window (w,h).
The default x-coordinate assumes a screen of
width 1280, and a rendering window of width 600
with a 10-pixel boundary. You can control these
parameters from the command line.
bool haveX=-1, haveY=-1, haveW=-1, haveH=-1,
haveSize=-1;
If TRUE, the processed scene graph is written to a
.csb file and not rendered. See “Reading and
Writing Scene-Graph Files: The Extendable
Loading Class opGenLoader” on page 30.
bool writeCSB;
You can use several techniques to develop
connected primitives that accelerate the rendering
process. See “Creating OpenGL Connected
Primitives” on page 100.
bool doTriStrip, doTriFan, doTriFanStrip,
doMPTriFanStrip;
int x=1280-600-10, y=0, w=600, h=600;
int minFanSize;
bool doRandomTriStrip;
// Color the tstrips with a random color
69
Chapter 4: Scene Graph Tuning With the optimizeDemo Application
Command-Line Control Parameters (cont.)
You can use either of two simplification
algorithms to remove triangles from a mesh. See
“Successive Relaxation Algorithm:
opSRASimplify” on page 115 and “Rossignac
Simplification Algorithm: opLatticeSimplify” on
page 118.
bool doSRASimplify;
bool SRApercent,SRAcount,SRAestimate;
float percent;
float fAngle;
int polyCount;
bool doLatticeSimplify;
There are several techniques to rearrange triangles
in a scene graph to reflect their positions in space
and facilitate cull traversals. See Chapter 8,
“Organizing the Scene Graph Spatially.”
bool combineGSet;
bool spatialize, geospatialize;
int minGoal,maxGoal;
bool writeOutput;
You can place simplified and unsimplified scene
graphs under a csLOD node.
bool LODfiles, makeLOD;
See “Detail Culling” on page 135.
bool
float
doDetail;
detail_ratio;
bool
float
doRootRadius;
root_radius;
bool
float
doScale;
scale_factor;
bool
showDelete;
bool
doDeleteSurf;
You can interactively assign colors to objects. See
“Interaction With a Rendered Object:
opPickDrawImpl” on page 156.
bool
enableColoring;
char
*colorTagFile;
char
*colorTag;
bool
doColorTag;
colorTable *cTable = NULL;
char
*colorFile;
bool
bool
70
doRemoveEmptyGrp;
removeColors;
optimizeDemo Code
Get Command-Line Parameters
Specify the threshhold distance between points
below which they are considered identical when
building topology. See “Summary of Scene Graph
Topology: opTopo” on page 180.
bool
opReal
Specify the background color for the rendering
window and the model orientation. These settings
are controlled by opViewer options. See “Viewing
Class: opViewer” on page 33.
bool haveBackgroundColor;
Specify control parameters for tessellation, and
the type of tessellator (for example for general
parametric surfaces or for NURBS surfaces). See
“Tessellating Parametric Surfaces” on page 295.
If tessType is equal to zero, no tessellation is
performed. The main use for this option is in batch
mode to convert file formats and possibly store
topology information; you can read in a .iv file and
write the scene graph without tessellations to a
.csb file. Depending on the topology-build
command-line option, the output could have
topology information. See “Reading and Writing
Scene-Graph Files: The Extendable Loading Class
opGenLoader” on page 30.
By default, build the best topology. See
Chapter 12, “Creating and Maintaining Surface
Topology.”
You must supply a file with the scene graph. All
other command-line control parameters are
optional.
haveTopoTol;
topoTol;
float backgroundRed, backgroundGreen,
backgroundBlue, backgroundAlpha;
bool
float
haveRotation;
vx, vy, vz, angle;
bool
float
haveTranslation;
tx, ty, tz;
bool
haveChordalTol = -1;
opReal
chordalTol = 0.01; bool haveSamples;
int
samples;
bool
haveTessType = -1;
char
*tessType = NULL;
// Initialize this since cmdline args may modify
bool
isOnePass = false;
args.defRequired( “%s”,
“”,
&filename);
71
Chapter 4: Scene Graph Tuning With the optimizeDemo Application
Get Command-Line Parameters (cont.)
args.defOption( “-width %d”,
“-width ”,
&haveW, &w );
args.defOption( “-height %d”,
“-height ”,
&haveH, &h );
args.defOption( “-size %d”,
“-size ”,
&haveSize, &w );
args.defOption( “-xpos %d”,
“-xpos ”,
&haveX, &x );
args.defOption( “-ypos %d”,
“-ypos ”,
&haveY, &y );
args.defOption( “-tristrip”,
“-tristrip”,
&doTriStrip );
args.defOption( “-trifan”,
“-trifan”,
&doTriFan);
args.defOption( “-trifanstrip %d”,
“-trifanstrip ”,
&doTriFanStrip, &minFanSize );
args.defOption( “-mptrifanstrip %d”,
“-mptrifanstrip ”,
&doMPTriFanStrip,&minFanSize );
args.defOption( “-detail %f”,
“-detail ”,
&doDetail, &detail_ratio);
args.defOption( “-rootRadius %f”,
“-rootRadius ”,
&doRootRadius, &root_radius);
args.defOption( “-simplify”,
“-simplify”,
&doSRASimplify );
72
optimizeDemo Code
Get Command-Line Parameters (cont.)
args.defOption( “-rossignac %f”,
“-rossignac ”,
&doLatticeSimplify,
&gridSpacing );
The target of the simplification can be specified as
a percentage of the original number of triangles,
or as a exact number. See “Successive Relaxation
Algorithm: opSRASimplify” on page 115.
args.defOption( “-simpPercent %f %f “,
“-simpPercent
”,
&SRApercent,
&percent,
&fAngle);
args.defOption( “-simpCount %d %f “,
“-simpCount ”,
&SRAcount,
&polyCount,
&fAngle);
args.defOption( “-simpEstimate”,
“-simpEstimate, for quick estimate of resulting
model”,
&SRAestimate);
You can render individual csTriStrips in differing
colors, to see their sizes.See “Creating OpenGL
Connected Primitives” on page 100; and “Specify
Coloring of New csGeoSets: opColorGenerator”
on page 332.
args.defOption( “-tristripRandom”,
“-tristripRandom, for random colors”,
&doRandomTriStrip);
args.defOption( “-scale %f”,
“-scale ”,
&doScale, &scale_factor);
args.defOption( “-batch %s”,
“-batch
Source Exif Data:
File Type : PDF
File Type Extension : pdf
MIME Type : application/pdf
PDF Version : 1.1
Linearized : No
Page Count : 428
Create Date : 1999:09:14 18:24:16
Producer : Acrobat Distiller 3.02
EXIF Metadata provided by EXIF.tools