-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicUsage.tex
1201 lines (983 loc) · 51.3 KB
/
BasicUsage.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% -*- latex -*-
\chapter{Basic Usage}
\label{chap:Basic_Usage}
In this chapter we describe in greater detail the basic features of \IceT.
The tutorial given in Chapter~\ref{chap:Tutorial} is a good place to
start building your applications. You can then consult this chapter and
later ones for more details on the operations as well as descriptions of
further features.
Prototypes for the majority of \IceT types, functions, and identifiers can
be found in the \index{IceT.h}\textC{IceT.h} header file. If you are using
\OpenGL for rendering, which is common, you will probably want to include
the header \index{IceTGL.h}\textC{IceTGL.h}. You will also almost always
need to include the header \index{IceTMPI.h}\textC{IceTMPI.h}.
Chapter~\ref{chap:Communicators} provides more details on this last
header file's function.
\begin{code}
#include <IceT.h>
#include <IceTGL.h>
#include <IceTMPI.h>
\end{code}
\section{The State Machine}
\label{sec:Basic_Usage:The_State_Machine}
\index{state|(}
The \IceT API borrows many concepts from \index{OpenGL}OpenGL. One major
concept taken is that of a state machine. At all times \IceT maintains a
current state. The state can influence the operations that \IceT makes,
and \IceT's operations can modify the state.
\index{context!\IceT|(}
\IceT can manage multiple collections of state at the same time. It does
this by associating each state with a
\keyterm{context}. At any given time, there is at
most one active context. Any \IceT function called works using the current
active context.
Contexts are created and destroyed with \CFunc{icetCreateContext} and
\CFunc{icetDestroyContext}, respectively.
\begin{Table}{3}
\CType{IceTContext}\textC{ }\CFunc{icetCreateContext}\textC{(}&\CType{IceTCommunicator}&\CArg{comm}\quad\textC{);}
\end{Table}
\begin{Table}{3}
\textC{void }\CFunc{icetDestroyContext}\textC{(}&\CType{IceTContext}&\CArg{context}\quad\textC{;}
\end{Table}
These functions work with an object of type \CType{IceTContext}.
\CType{IceTContext} is an opaque type; you are not meant to directly access
it. Instead, you pass the object to functions to do the work for you.
The \CFunc{icetCreateContext} function requires an object of type
\CType{IceTCommunicator}. This is another opaque type that is described in
more detail in Chapter~\ref{chap:Communicators}. For now, just know that
you can create one from an MPI communicator using the
\CFunc{icetCreateMPICommunicator} function.
\begin{Table}{3}
\CType{IceTCommunicator}\textC{ }\CFunc{icetCreateMPICommunicator}\textC{(} \\
\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad
\CTypeExternal{MPI\_Comm}\quad\CArg{mpi\_comm}\quad\textC{);}
\end{Table}
\begin{Table}{3}
\textC{void }\CFunc{icetDestroyMPICommunicator}\textC{(}&\CType{IceTCommunicator}&\CArg{comm}\quad\textC{);}
\end{Table}
Also be aware that if you plan to use \IceT's \OpenGL layer, you will need
to initialize it with \CFunc{icetGLInitialize}. You can query whether the
\OpenGL layer has be initialized with \CFunc{icetGLIsInitialized}.
\begin{Table}{3}
\textC{void }\CFunc{icetGLInitialize}\textC{(}&\textC{void}&\textC{);}
\end{Table}
\begin{Table}{3}
\textC{IceTBoolean }\CFunc{icetGLIsInitialized}\textC{(}&\textC{void}&\textC{);}
\end{Table}
It is good practice to call \CFunc{icetGLInitialize} immediately after
creating a context with \CFunc{icetCreateContext} to always ensure that the
\OpenGL layer is ready to be used (assuming you plan to use it).
The following code gives the common boilerplate for setting up your initial
\IceT context.
\begin{code}
#include <IceT.h>
#include <IceTGL.h>
#include <IceTMPI.h>
int main(int argc, char **argv)
{
IceTCommunicator icetComm;
IceTContext icetContext;
/* Setup MPI. */
MPI_Init(&argc, &argv);
/* Setup an IceT context. If we are only creating one, this context will
* always be current. */
icetComm = icetCreateMPICommunicator(MPI_COMM_WORLD);
icetContext = icetCreateContext(icetComm);
icetDestroyMPICommunicator(icetComm);
/* Initialize the OpenGL layer. */
icetGLInitialize();
/* Start your parallel rendering program here. */
/* Cleanup IceT and MPI. */
icetDestroyContext(icetContext);
MPI_Finalize();
return 0;
}
\end{code}
Any number of contexts may be created, each with its own associated state.
At any given time, a single given context is
\index{context!current}\keyterm{current}. All \IceT operations are applied
with the state attached to the current context. A handle to the current
\IceT context can be retrieved with the \CFunc{icetGetContext} function,
and he current context can be changed by using the \CFunc{icetSetContext}
function.
\begin{Table}{3}
\CType{IceTContext}\textC{ }\CFunc{icetGetContext}\textC{(}&\textC{void}&\textC{);}
\end{Table}
\begin{Table}{3}
\textC{void }\CFunc{icetSetContext}\textC{(}&\CType{IceTContext}&\CArg{context}\quad\textC{);}
\end{Table}
Changing the context is a fast and easy way to swap states. This could be
used, for example, to switch between rendering modes. One context could be
used for a full resolution image, and another could use
\index{image!inflation}\keyterm{image inflation} (described in
Chapter~\ref{sec:Customizing_Compositing:Image_Inflation}) to make faster
but coarser images during interaction.
When a context is created, its state is initialized to default values. You
can effectively ``duplicate'' a context by copying the state of one context
to another using the \CFunc{icetCopyState} function.
\begin{Table}{3}
\textC{void }\CFunc{icetCopyState}\textC{(}&\CType{IceTContext}&\CArg{dest}\textC{,} \\
&\textC{const }\CType{IceTContext}&\CArg{src}\quad\textC{);}
\end{Table}
\index{context!\IceT|)}
The state of a context comprises a group of key/value pairs. The state can
be queried by using any of the \CFunc{icetGet} functions.
\begin{Table}{3}
\textC{void }\icetGetDoublev\textC{(}&\textC{IceTEnum}&\CArg{pname}\textC{,} \\
&\textC{IceTDouble *}&\CArg{params}\quad\textC{);}
\end{Table}
\begin{Table}{3}
\textC{void }\icetGetFloatv\textC{(}&\textC{IceTEnum}&\CArg{pname}\textC{,} \\
&\textC{IceTFloat *}&\CArg{params}\quad\textC{);}
\end{Table}
\begin{Table}{3}
\textC{void }\icetGetIntegerv\textC{(}&\textC{IceTEnum}&\CArg{pname}\textC{,} \\
&\textC{IceTInt *}&\CArg{params}\quad\textC{);}
\end{Table}
\begin{Table}{3}
\textC{void }\icetGetBooleanv\textC{(}&\textC{IceTEnum}&\CArg{pname}\textC{,} \\
&\textC{IceTBoolean *}&\CArg{params}\quad\textC{);}
\end{Table}
\begin{Table}{3}
\textC{void }\icetGetPointerv\textC{(}&\textC{IceTEnum}&\CArg{pname}\textC{,} \\
&\textC{IceTVoid **}&\CArg{params}\quad\textC{);}
\end{Table}
The valid keys that can be used in the \CFunc{icetGet} functions are listed
in the \CFunc{icetGet} documentation starting on
page~\pageref{manpage:icetGet}. There is no way to directly set these
state variables. Instead, they are set either by \IceT configuration
functions or indirectly as part of the operation of \IceT. The
documentation for \CFunc{icetGet} also describes which functions can be
used to set each state entry (assuming the user has control of that state
entry).
There is a special set of state entries that toggle \IceT options. Although
you can query this state with the \icetGetBooleanv function, it is more
typical to use the \CFunc{icetIsEnabled} function. Also unlike the other
state variables, these variables can be directly manipulated with the
\CFunc{icetEnable} and \CFunc{icetDisable} functions.
\begin{Table}{4}
\textC{IceTBoolean }\CFunc{icetIsEnabled}\textC{(}&\textC{IceTEnum}&\CArg{pname}&\textC{);}
\end{Table}
\begin{Table}{4}
\textC{void }\icetEnable&\textC{(}&\textC{IceTEnum}&\CArg{pname}\quad\textC{);}
\end{Table}
\begin{Table}{4}
\textC{void }\icetDisable&\textC{(}&\textC{IceTEnum}&\CArg{pname}\quad\textC{);}
\end{Table}
The options queried with \CFunc{icetIsEnabled} and manipulated with
\CFunc{icetEnable} and \CFunc{icetDisable} are listed in the
\CFunc{icetEnable} documentation starting on
page~\pageref{manpage:icetEnable}.
\index{state|)}
\section{Diagnostics}
\label{sec:Basic_Usage:Diagnostics}
\index{diagnostics|(}
The \IceT library has a mechanism for reporting diagnostics. There are
three levels of diagnostics. \index{error}\keyterm{Errors} are anomalous
conditions that \IceT considers a critical failure. An occurrence of an
error generally means that the future \IceT operations will have undefined
behavior. When \IceT is compiled in debug mode, a seg fault is
intentionally raised when an error occurs to make it easier to attach a
debugger to the point where the error occurred.
\index{warning}\keyterm{Warnings} are detections of anomalous conditions
that are not as severe as errors. When a warning occurs, the current
operation may produce the incorrect results, but future operations should
continue to work.
\IceT also can also provide a large volume of \index{debug}\keyterm{debug}
messages. These messages simply indicate the status of \IceT operations as
they progress. They are generally of no use to anyone who is not trying to
develop or debug \IceT operations.
\IceT diagnostics are controlled with the \CFunc{icetDiagnostics} function.
\begin{Table}{3}
\textC{void }\CFunc{icetDiagnostics}\textC{(}&\textC{IceTBitField}&\CArg{mask}\quad\textC{);}
\end{Table}
The \CFunc{icetDiagnostics} function takes a set of flags that can me or-ed
together. The diagnostics for errors, warnings, and debug statements can
be set by passing the \CEnum{ICET\_DIAG\_ERRORS},
\CEnum{ICET\_DIAG\_WARNINGS}, and \CEnum{ICET\_DIAG\_DEBUG} flags, respectively.
Turning on warnings implicitly turns on errors and turning on debug
statements implicitly turns on errors and warnings (although there is no
problem with redundantly specifying these flags).
\IceT has the ability to report diagnostics either on all processes or only
on the \index{root~process}\keyterm{root process} (the process with rank
0). This behavior is controlled by the \CEnum{ICET\_DIAG\_ROOT\_NODE} and
\CEnum{ICET\_DIAG\_ALL\_NODES} flags. Many diagnostic messages occur on
all nodes when they occur, so reporting only on node 0 can greatly reduce
the number of messages with which to contend. However, messages can differ
between processes or may not occur on all processes.
The special flags \CEnum{ICET\_DIAG\_FULL} and \CEnum{ICET\_DIAG\_OFF} turn
all possible diagnostics on and all diagnostics completely off,
respectively.
By default, \IceT displays errors and warnings on all nodes. You can get
the current diagnostic level by calling \CFunc{icetGet} with
\CEnum{ICET\_DIAGNOSTIC\_LEVEL}.
\index{diagnostics|)}
\section{Display Definition}
\label{sec:Basic_Usage:Display_Definition}
\index{display~definition|(}
\index{tile~definition|(}
\IceT assumes that the tiled display it is driving has each tile connected
to the graphics output of one of the processes in the parallel job in which
it is running. This type of arrangement is natural for any tiled display
driven by a graphics cluster, and is the delivery method of many graphics
APIs. %\lcite{Buck00,Humphreys00,Humphreys02,Samanta99}
\IceT defines the configuration of a tiled display by using a
\index{logical~global~display}\index{global~display}\keyterm{logical global
display} with an infinite \footnote{Well, OK. The logical global display
only stretches as far as the 32-bit numbers that are used to define
viewports. But that's still way bigger than any physical display that we
can possibly conceive, so conceptually we call it infinite.} number of
pixels in both the horizontal and vertical directions. The definition of
each tile comprises the identifier for the process connected to the
physical projection and the \index{viewport}\keyterm{viewport} (position
and size) of the tile in the global display. \IceT implicitly defines the
rectangle that tightly encompasses all of the tile viewports as the
viewable area and snaps the viewing region (defined by the OpenGL viewing
matrices) to this area.
\begin{figure}
\centering
\includegraphics{images/ExampleTileConfig}
\caption[Defining a tile display.]{Defining a tile display with viewports
in a logical global display. Three possible tile arrangements are
shown. The bounds of each tile is drawn with the viewport given
inside. The viewable area is shown with a dashed line.}
\label{fig:BasicUsage:tile_layout}
\end{figure}
Figure~\ref{fig:BasicUsage:tile_layout} shows some possible tile
arrangements. Mullions or overlaps of the tiles in the physical display
can be represented by the spacing or overlap of the viewports in the
logical display. \IceT does not require the tile layout to have any
regularity. Chaotic layouts like that shown in the right image of
Figure~\ref{fig:BasicUsage:tile_layout} are legal, although probably not
very useful. It is allowed, and in fact encouraged, to have processes that
are not directly connected to the tiled display. These
\index{non-display~process}\keyterm{non-display} processes still contribute
to the image compositing work and will reduce the overall time to render an
image.
The display is defined using the \CFunc{icetResetTiles} and
\CFunc{icetAddTile} functions. Any previous tile definition is first
cleared out using \CFunc{icetResetTiles} and new tiles are added, one at a
time, using \CFunc{icetAddTile}.
\begin{Table}{3}
\textC{void }\CFunc{icetResetTiles}\textC{(}&\textC{void}&\textC{)}
\end{Table}
\begin{Table}{3}
\textC{int }\CFunc{icetAddTile}\textC{(}&\textC{IceTInt}&\CArg{x}\textC{,} \\
&\textC{IceTInt}&\CArg{y}\textC{,} \\
&\textC{IceTSizeType}&\CArg{width}\textC{,} \\
&\textC{IceTSizeType}&\CArg{height}\textC{,} \\
&\textC{int}&\CArg{display\_rank}\quad\textC{);}
\end{Table}
Each tile is specified using screen coordinates in the logical global
display: the position of the lower left corner and the width and height of
the tile. Each tile also has a \index{display~process}\keyterm{display
process} associated with it. After an image is completely rendered and
composited, the screen section belonging to this tile will be placed in the
process at the given rank.
The following code demonstrates a common example for establishing the tile
layout: a grid of projectors. The arrangement of projectors in this
example assume that the projectors are connected to processes in the order
of left to right and then top to bottom, which is common. Note, however,
that \IceT defines its logical global display with $y$ values from the
bottom up like OpenGL does.
\begin{code}
icetResetTiles();
for (row = 0; row < num_tile_rows; row++) {
for (column = 0; column < num_tile_columns; column++) {
icetAddTile(column*TILE_WIDTH, (num_tile_rows-row-1)*TILE_HEIGHT,
TILE_WIDTH, TILE_HEIGHT,
row*num_tile_columns + column);
}
}
\end{code}
\index{mullion}\keyterm{Mullions} are added by simply spacing the tiles
apart from each other in the logical global display. Because they are
defined in the logical global display, physical dimensions of the mullions
must first be converted to pixels using the dot pitch of the displays. The
following code adds mullions between all of the tiles.
\begin{code}
icetResetTiles();
for (row = 0; row < num_tile_rows; row++) {
for (column = 0; column < num_tile_columns; column++) {
icetAddTile(column*(TILE_WIDTH + x_mullion),
(num_tile_rows-row-1)*(TILE_HEIGHT + y_mullion),
TILE_WIDTH, TILE_HEIGHT,
row*num_tile_columns + column);
}
}
\end{code}
An equally common use for \IceT is to render images in parallel to a single
display. In this \index{single-tile~rendering}\keyterm{single-tile
rendering} mode, we simply create a single tile whose image will be
placed in the GUI of some application. This is done by either using the
OpenGL context of the GUI as part of the \IceT rendering process or by
grabbing the image of the single tile and copying into the GUI. The
example code below sets up \IceT to create a single image that is
accessible on the root process.
\begin{code}
icetResetTiles();
icetAddTile(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0);
\end{code}
\IceT indexes the tiles in the order that they are defined with
\CFunc{icetAddTile}. You can get the current definition of the tile
display from a number of state variables, which can be retrieved as always
with \CFunc{icetGet}. \CEnum{ICET\_NUM\_TILES} stores the number of tiles
that are defined (the number of times \CFunc{icetAddTile} was called).
\CEnum{ICET\_TILE\_VIEWPORTS} stores an array with all of the dimensions of
each tile. For each tile, \CEnum{ICET\_TILE\_VIEWPORTS} contains the four
\index{viewport}values $\langle x, y, width, height \rangle$, stored
consecutively, corresponding to the values passed to \CFunc{icetAddTile}.
\CEnum{ICET\_DISPLAY\_NODES} stores an array giving the rank of the
\index{display~process}display process displaying that tile. Each process
can also query the \CEnum{ICET\_TILE\_DISPLAYED} variable to see which tile
is displayed locally. \CEnum{ICET\_TILE\_DISPLAYED} is set to $-1$ on
every process that does not display a tile.
You can get information about the display geometry as a whole through
\CEnum{ICET\_GLOBAL\_VIEWPORT}. This variable stores the four-tuple
$\langle x, y, width, height \rangle$. $x$ and $y$ are placed at the
leftmost and lowest position of all the tiles, and $width$ and $height$ are
just big enough for the viewport to cover all tiles.
The \IceT image compositor remains decoupled from the rendering system.
Calling \CFunc{icetAddTile} will not create a display context or renderable
window for the tile. That responsibility is left to the calling
application. When using \IceT in \index{single-tile~rendering}single-tile
rendering mode, the rendering system should be set to produce images of
that single tile's size. When driving a physical tiled display, each
display process must create a window that covers the entire display. It is
also a good idea to disable the mouse cursor in these windows.
Note that the size of the tiles do not have to match each other. Also, the
size of the images that your application generates do not have to match the
size of any of the tiles. There is, however, a constraint that the
generated images on all processes must be at least as large as the largest
tile in each dimension. To help you maintain that constraint, \IceT stores
the largest tile dimensions in the \CEnum{ICET\_TILE\_MAX\_WIDTH} and
\CEnum{ICET\_TILE\_MAX\_HEIGHT} state variables.
\IceT must know in advanced the size of images that your application will
render. If you are using \IceT's \OpenGL layer, \IceT will automatically
know the size of the images you generate based off of the current \OpenGL
viewport (retrieved with the \CEnum{GL\_VIEWPORT} \OpenGL state variable).
Otherwise, you can specify the size of images the application generates
with \CFunc{icetPhysicalRenderSize}. If you are not using the \OpenGL
layer and you have not called \CFunc{icetPhysicalRenderSize}, \IceT assumes
that you will generate images of width \CEnum{ICET\_TILE\_MAX\_WIDTH} and
height \CEnum{ICET\_TILE\_MAX\_HEIGHT}. The actual expected rendered image
size is stored in the \CEnum{ICET\_PHYSICAL\_RENDER\_WIDTH} and
\CEnum{ICET\_PHYSICAL\_RENDER\_HEIGHT} state variables.
Although counterintuitive, it is often more efficient to create images that
are larger than any tile. This situation may be necessary when using
\index{image!inflation}image inflation (see
Chapter~\ref{sec:Customizing_Compositing:Image_Inflation}). Even when not
using image inflation, larger rendered images can save a significant amount
of rendering time. \IceT can use the larger images to potentially render
in one shot an object that is larger than any of the tiles.
\index{display~definition|)}
\index{tile~definition|)}
\section{Strategies}
\label{sec:Basic_Usage:Strategies}
\index{strategy|(}
\IceT contains several algorithms for performing image compositing. The
overall algorithm used to render and composite an image is called a
strategy, named after the ``Gang of Four'' strategy pattern.\footnote{Erich
Gamma, Richard Helm, Ralph Johnson, and John Vlissides. \emph{Design
Patterns}. Addison-Wesley, 1994. ISBN 0-201-63361-2.} The strategy
is set using the \CFunc{icetStrategy} function.
\begin{Table}{3}
\textC{void }\CFunc{icetStrategy}\textC{(}&\textC{IceTEnum}&\CArg{strategy}\quad\textC{);}
\end{Table}
\IceT defines the following strategies that can be passed to
\CFunc{icetStrategy}. These strategies are discussed in more detail in
Chapter~\ref{chap:Strategies}.
\input{enumerations/strategy.tex}
You can get a human-readable name using the \CFunc{icetGetStrategyName}
function.
\begin{Table}{3}
\textC{const char *}\CFunc{icetGetStrategyName}\textC{(}&\textC{void}&\textC{);}
\end{Table}
The algorithms in \IceT's strategies are specially designed to composite
data defined on multiple tiles. Some of these algorithms, namely
\CEnum{ICET\_STRATEGY\_REDUCE} and \CEnum{ICET\_STRATEGY\_SEQUENTIAL},
operate at least in part by compositing single images together. \IceT also
comes with multiple separate strategies for performing this single image
compositing, and this can be selected with the
\CFunc{icetSingleImageStrategy} function.
\begin{Table}{3}
\textC{void }\CFunc{icetSingleImageStrategy}\textC{(}&\textC{IceTEnum}&\CArg{strategy}\quad\textC{);}
\end{Table}
\IceT defines the following single image strategies that can be passed to
\CFunc{icetSingleImageStrategy}. These strategies are discussed in more
detail in Chapter~\ref{chap:Strategies}.
\input{enumerations/single_image_strategy.tex}
By default \IceT sets the single image strategy to
\CEnum{ICET\_SINGLE\_IMAGE\_STRATEGY\_AUTOMATIC} when a context is created.
This is the single image strategy that will be used if no other is
selected.
You can get a human-readable name using the
\CFunc{icetGetSingleImageStrategyName} function.
\begin{Table}{3}
\textC{const char *}\CFunc{icetGetSingleImageStrategyName}\textC{(}&\textC{void}&\textC{);}
\end{Table}
\index{strategy|)}
\section{Drawing Callback}
\label{sec:Basic_Usage:Drawing_Callback}
\index{drawing~callback|(}
Most compositing engines will simply take a group of images and combine
them together. This approach, however, can be unreasonable when
compositing the high resolution images on a large tiled display. Although
\IceT can accept a single rendered image when that is convenient, \IceT can
also manage rendering when it is problematic to create display-sized images
that are larger than any buffer rendering hardware can directly produce.
To manage these problematic cases, the \IceT algorithms deal with pieces of
the overall image. The image pieces are created on demand. As such, \IceT
may require the same geometry to be rendered multiple times in a single
frame. \IceT provides the application with the most flexible way to define
the rendering process: with a \keyterm{drawing callback}.
A drawing callback is simply a function that your application provides
\IceT. When \IceT needs an image, it will provide the drawing callback
with the projection matrices for the section of the display being
rendered. The drawing callback then returns the image rendered to those
projection matrices.
\IceT may call the drawing callback several times to create a single tiled
image or not at all if the current bounds lie outside the current view
frustum. This can have a subtle but important impact on the behavior of
the drawing callback. For example, counting frames by incrementing a frame
counter in the drawing callback is obviously wrong (although you could
count how many times a render occurs). The drawing callback should also
leave the rendering system in a state such that it will be correct for a
subsequent run of the drawing callback. Any state that is assumed to be
true on entrance to the drawing callback should also be true on return.
It is also possible to use \IceT without callbacks, which is sometimes more
convenient for applications. Rendering without callbacks is discussed in
the following section on rendering.
\subsection{Generic Drawing Callback}
\label{sec:Basic_Usage:Drawing_Callback:Generic}
There are two versions of drawing callbacks. The first version is a
generic callback set with \CFunc{icetDrawCallback}. This callback is used
in conjunction with the \CFunc{icetDrawFrame} function (described in the
next section).
\begin{Table}{3}
\multicolumn{3}{l}{
\textC{typedef void (*}\CType{IceTDrawCallbackType}\textC{)(}
} \\
\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad
&\textC{const IceTDouble *}&\CArg{projection\_matrix}\textC{,} \\
&\textC{const IceTDouble *}&\CArg{modelview\_matrix}\textC{,} \\
&\textC{const IceTFloat *}&\CArg{background\_color}\textC{,} \\
&\textC{const IceTInt *}&\CArg{readback\_viewport}\textC{,} \\
&\CType{IceTImage}&\CArg{result}\quad\textC{)}
\end{Table}
\begin{Table}{3}
\textC{void }\CFunc{icetDrawCallback}\textC{(}&\CType{IceTDrawCallbackType}&\CArg{callback}\quad\textC{);}
\end{Table}
\CArg{callback} takes two projection matrices: \CArg{projection\_matrix}
and \CArg{modelview\_matrix}. Each of these arguments is a 16-value array
that represents a $4 \times 4$ transformation of homogeneous coordinates.
The arrays store the matrices in \index{column-major~order}column-major
order. Thus, if the values in \CArg{projection\_matrix} are $(p[0],
p[1],... p[15])$ and the values in \CArg{modelview\_matrix} are $(m[0],
m[1],... m[15])$, then a vertex in object space is transformed into
normalized screen coordinates by the sequence of operations
\begin{displaymath}
\left[
\begin{array}{cccc}
p[0] & p[4] & p[8] & p[12] \\
p[1] & p[5] & p[9] & p[13] \\
p[2] & p[6] & p[10] & p[14] \\
p[3] & p[7] & p[11] & p[15]
\end{array}
\right]
\left[
\begin{array}{cccc}
m[0] & m[4] & m[8] & m[12] \\
m[1] & m[5] & m[9] & m[13] \\
m[2] & m[6] & m[10] & m[14] \\
m[3] & m[7] & m[11] & m[15]
\end{array}
\right]
\left[
\begin{array}{c}
v[0] \\ v[1] \\ v[2] \\ v[3]
\end{array}
\right]
\end{displaymath}
More explicitly, if you have a point $(x, y, z, 1)$ in object space stored
in a variable \textC{object\_coord}, you could transform that to world
space in the callback with code like this.
\begin{code}
for (row = 0; row < 4; row++) {
world_coord[row] = 0.0;
for (i = 0; i < 4; i++) {
world_coord[row] += modelview_matrix[row + 4*i] * object_coord[i];
}
}
\end{code}
Likewise, to transform the \textC{world\_coord} to normalized screen
coordinates, you could apply the following code.
\begin{code}
for (row = 0; row < 4; row++) {
screen_coord[row] = 0.0;
for (i = 0; i < 4; i++) {
screen_coord[row] += projection_matrix[row + 4*i] * world_coord[i];
}
}
\end{code}
If your rendering system has no need to find the world coordinates of
points, you can combine the two matrices by multiplying them together like
this.
\begin{code}
for (row = 0; row < 4; row++) {
for (column = 0; column < 4; column++) {
full_matrix[row + 4*column] = 0.0;
for (i = 0; i < 4; i++) {
full_matrix[row + 4*column] +=
projection_matrix[row + 4*i] * modelview_matrix[k + 4*column];
}
}
}
\end{code}
Normalized screen coordinates are such that everything projected onto the
image has coordinates in the range $[-1,1]$ (after dividing by the ``w''
homogeneous coordinate). The x and y coordinates have to be shifted to get
the corresponding pixel location. The normalized screen coordinates are
projected to span the physical render size (see
\CFunc{icetPhysicalRenderSize}), which may differ from the size of any
particular tile. Also, if you are outputting depth values, \IceT expects
values in the range $[0,1]$, so you will have to shift those as well. Here
is a pedantic code segment to do this final transformation.
\begin{code}
icetGetIntegerv(ICET_PHYSICAL_RENDER_WIDTH, &image_width);
icetGetIntegerv(ICET_PHYSICAL_RENDER_HEIGHT, &image_height);
/* Alternatively, you could get the width and height from the image passed */
/* to the callback like this. */
/* image_width = icetImageGetWidth(result); */
/* image_height = icetImageGetHeight(result); */
pixel_x = (int)(image_width*0.5*(screen_coord[0]/screen_coord[3] + 1.0));
pixel_y = (int)(image_height*0.5*(screen_coord[1]/screen_coord[3] + 1.0));
depth = 0.5*(screen_coord[2]/screen_coord[3] + 1.0);
\end{code}
The drawing callback should initialize its backdrop to the
\CArg{background\_color}, which may be different than the background color
passed to \CFunc{icetDrawFrame}.
The resulting image should be rendered (or copied) into the
\CType{IceTImage}, \CArg{result}, passed to the callback. The image will
be sized by the physical render width and height and its format will
conform to that set by \CFunc{icetSetColorFormat} and
\CFunc{icetSetDepthFormat}. You can get the buffers of the image with the
\icetImageGetColor and \icetImageGetDepth functions. Data written to these
buffers will become part of the image. \IceT's image functions are
described in more detail in the following section starting on
page~\pageref{sec:Basic_Usage:Image_Objects}.
\IceT will always send the drawing callback an image sized by the physical
render viewport specified by \CFunc{icetPhysicalRenderSize} for
convenience. However, \IceT often needs only a subset of these pixels.
\IceT tells the drawing callback the pixels it actually uses with the
\CArg{readback\_viewport} parameter. \CArg{readback\_viewport} contains 4
integers specifying a region of pixels that \IceT will use. The first two
value specify the lower-left corner of the region and the next two specify
the width and height of the region.
For example, if the \CArg{readback\_viewport} is set to $(10, 15, 100,
75)$, then \IceT will use only the pixels in the square between x values 10
and 109 and y values between 15 and 89 (both inclusive). All other pixels
in the image will be ignored. It is not an error to provide values for the
other pixels, but it is a waste of computation.
\subsection{OpenGL Drawing Callback}
\label{sec:Basic_Usage:Drawing_Callback:OpenGL}
If you are rendering with \OpenGL, then you can remove many of the
complexities of defining a callback by using \CFunc{icetGLDrawCallback} in
conjunction with \CFunc{icetGLDrawFrame}.
\textC{typedef void (*} \CType{IceTGLDrawCallbackType}\textC{)( void );}
\begin{Table}{3}
\textC{void }\CFunc{icetGLDrawCallback}\textC{(}&\CType{IceTGLDrawCallbackType}&\CArg{callback}\quad\textC{);}
\end{Table}
The \OpenGL version of the drawing callback takes no arguments. It simply
issues the appropriate \OpenGL calls to render the geometry. \IceT
internally takes care of setting the appropriate transformations and clear
color, and then reads back your data from the buffer specified by
\CFunc{icetGLSetReadBuffer} after the drawing callback returns.
The \OpenGL drawing callback should \emph{not} modify the
\CEnum{GL\_PROJECTION\_MATRIX} as this would cause \IceT to place image
data in the wrong location in the tiled display and improperly cull
geometry. It is acceptable to add transformations to
\CEnum{GL\_MODELVIEW\_MATRIX}, but the bounding vertices given with
\CFunc{icetBoundingVertices} or \CFunc{icetBoundingBox} (see the following
section) are assumed to already be transformed by any such changes to the
modelview matrix. Also, \CEnum{GL\_MODELVIEW\_MATRIX} must be restored
before the draw function returns. Therefore, any changes to
\CEnum{GL\_MODELVIEW\_MATRIX} are to be done with care and should be
surrounded by a pair of glPushMatrix and glPopMatrix functions.
It is also important that the \OpenGL drawing callback \emph{not} attempt
the change the clear color. In some compositing modes, \IceT needs to
read, modify, and change the background color. These operations will be
lost if the drawing callback changes the background color, and severe color
blending artifacts may result.
\subsection{Specifying Geometry Bounds}
\label{sec:Basic_Usage:Drawing_Callback:Bounds}
\IceT can nominally call the drawing callback for every tile in the
display. However, in almost any real application each process has data
that demonstrates some spatial locality that causes it to be projected on a
relatively small section of the display. To give \IceT the information it
needs to prevent unnecessary renders, the application needs to provide the
bounds of the local geometry. This is done using either the
\CFunc{icetBoundingVertices} or the \CFunc{icetBoundingBox} function.
\begin{Table}{3}
\textC{void }\CFunc{icetBoundingVertices}\textC{(}&\textC{IceTInt}&\CArg{size}\textC{,} \\
&\textC{IceTEnum}&\CArg{type}\textC{,} \\
&\textC{IceTSizeType}&\CArg{stride}\textC{,} \\
&\textC{IceTSizeType}&\CArg{count}\textC{,} \\
&\textC{const IceTVoid *}&\CArg{pointer}\quad\textC{);}
\end{Table}
\begin{Table}{3}
\textC{void }\icetBoundingBoxd\textC{(}&\textC{IceTDouble}&\CArg{x\_min}\textC{,} \\
&\textC{IceTDouble}&\CArg{x\_max}\textC{,} \\
&\textC{IceTDouble}&\CArg{y\_min}\textC{,} \\
&\textC{IceTDouble}&\CArg{y\_max}\textC{,} \\
&\textC{IceTDouble}&\CArg{z\_min}\textC{,} \\
&\textC{IceTDouble}&\CArg{z\_max}\quad\textC{);}
\end{Table}
\begin{Table}{3}
\textC{void }\icetBoundingBoxf\textC{(}&\textC{IceTFloat}&\CArg{x\_min}\textC{,} \\
&\textC{IceTFloat}&\CArg{x\_max}\textC{,} \\
&\textC{IceTFloat}&\CArg{y\_min}\textC{,} \\
&\textC{IceTFloat}&\CArg{y\_max}\textC{,} \\
&\textC{IceTFloat}&\CArg{z\_min}\textC{,} \\
&\textC{IceTFloat}&\CArg{z\_max}\quad\textC{);}
\end{Table}
With the \CFunc{icetBoundingVertices} function, you specify a set of
vertices whose convex hull completely contains the geometry. The
\CFunc{icetBoundingBox} function is a convenience function that defines the
container as an axis aligned bounding box.
\index{drawing~callback|)}
\section{Rendering}
\label{sec:Basic_Usage:Rendering}
Once you have set up the \IceT state as described in the previous sections
of this chapter, you are ready to perform parallel rendering. Rendering is
initiated in \IceT by calling one of the draw frame functions.
\subsection{Generic Rendering}
\label{sec:Basic_Usage:Rendering:Generic}
There are two frame drawing functions. The first version is independent of
the rendering system and is used in conjunction with the callback set with
\CFunc{icetDrawCallback}. It is performed by calling
\CFunc{icetDrawFrame}.
\begin{Table}{3}
\CType{IceTImage}\textC{ }\CFunc{icetDrawFrame}\textC{(}
&\textC{const IceTDouble *}&\CArg{projection\_matrix}\textC{,} \\
&\textC{const IceTDouble *}&\CArg{modelview\_matrix}\textC{,} \\
&\textC{const IceTFloat *}&\CArg{background\_color}\quad\textC{);}
\end{Table}
Conceptually, calling \CFunc{icetDrawFrame} is similar to calling the
\index{drawing~callback}drawing callback directly. The arguments
\CArg{projection\_matrix}, \CArg{modelview\_matrix}, and
\CArg{background\_color} are the same as you would potentially pass the
callback (although \IceT is free to change them).
The \CArg{projection\_matrix} and \CArg{modelview\_matrix} are 16-value
arrays that represent $4 \times 4$ transformations of homogeneous coordinates.
The arrays store the matrices in \index{column-major~order}column-major
order. Thus, if the values in \CArg{projection\_matrix} are $(p[0],
p[1],... p[15])$ and the values in \CArg{modelview\_matrix} are $(m[0],
m[1],... m[15])$, then a vertex in object space is transformed into
normalized screen coordinates by the sequence of operations
For example, if your modelview matrix used a simple translation to move the
geometry in front of the camera, you would use a matrix like this.
\begin{displaymath}
\left[
\begin{array}{cccc}
1 & 0 & 0 & x \\
0 & 1 & 0 & y \\
0 & 0 & 1 & z \\
0 & 0 & 0 & 1
\end{array}
\right]
\end{displaymath}
The code to set the modelview matrix could look like this.
\begin{code}
modelview_matrix[ 0] = 1.0;
modelview_matrix[ 1] = 0.0;
modelview_matrix[ 2] = 0.0;
modelview_matrix[ 3] = 0.0;
modelview_matrix[ 4] = 0.0;
modelview_matrix[ 5] = 1.0;
modelview_matrix[ 6] = 0.0;
modelview_matrix[ 7] = 0.0;
modelview_matrix[ 8] = 0.0;
modelview_matrix[ 9] = 0.0;
modelview_matrix[10] = 1.0;
modelview_matrix[11] = 0.0;
modelview_matrix[12] = x;
modelview_matrix[13] = y;
modelview_matrix[14] = z;
modelview_matrix[15] = 1.0;
\end{code}
As another example, consider setting the projection matrix for the
perspective of a camera sitting at the origin facing down the $-z$ axis.
You could use a transformation matrix like this.
\begin{displaymath}
\begin{array}{c}
\left[
\begin{array}{cccc}
\frac{f \cdot height}{width} & 0 & 0 & 0 \\
0 & f & 0 & 0 \\
0 & 0 & -1 & -2near \\
0 & 0 & -1 & 0
\end{array}
\right] \\
f = \mathrm{cotangent}\left(\frac{fovy}{2}\right)
\end{array}
\end{displaymath}
The code to set the projection matrix could look like this.
\begin{code}
/* width, height: image dimensions */
/* fovy: field of view in the y direction */
/* zNear: distance from camera (at origin) to near clipping plane (at -zNear). */
f = 1.0/tan(0.5*fovy);
projection_matrix[ 0] = (f*height)/width;
projection_matrix[ 1] = 0.0;
projection_matrix[ 2] = 0.0;
projection_matrix[ 3] = 0.0;
projection_matrix[ 4] = 0.0;
projection_matrix[ 5] = f;
projection_matrix[ 6] = 0.0;
projection_matrix[ 7] = 0.0;
projection_matrix[ 8] = 0.0;
projection_matrix[ 9] = 0.0;
projection_matrix[10] = -1.0;
projection_matrix[11] = -1.0;
projection_matrix[12] = 0.0;
projection_matrix[13] = 0.0;
projection_matrix[14] = -2*zNear;
projection_matrix[15] = 0.0;
\end{code}
The \CArg{background\_color} is the color in which the background should be
initialized. It is the color of ``empty'' pixels and also the color to be
blended with any transparent geometry.
\CFunc{icetDrawFrame} returns an \CType{IceTImage} containing the composited
image displayed on this process. If the process is not displaying a tile,
then the contents of the image is undefined.
\subsection{OpenGL Rendering}
\label{sec:Basic_Usage:Rendering:OpenGL}
If you are rendering with \OpenGL, then you can remove many of the
complexities of defining projection matrices and displaying images by using
the \CFunc{icetGLDrawFrame} function in conjunction with the drawing
callback set with \CFunc{icetGLDrawCallback}.
\begin{Table}{3}
\textC{void}\quad\CFunc{icetGLDrawFrame}\textC{( void );}
\end{Table}
\CFunc{icetGLDrawFrame} is called in basically the same way as the \OpenGL
\index{drawing~callback}drawing callback would be called directly. First,
establish the \OpenGL state. Setting up the \CEnum{GL\_PROJECTION\_MATRIX}
before calling \CFunc{icetGLDrawFrame} is essential. It is also advisable
to set up whatever transformations in the \CEnum{GL\_MODELVIEW\_MATRIX}
that you can before calling \CFunc{icetGLDrawFrame}. \IceT will use and
modify these two matrices to render regions of the tiled display. The
drawing callback should behave as if neither of the matrices were modified.
By the time \CFunc{icetGLDrawFrame} completes, an image will have been
completely rendered and composited. If \CEnum{ICET\_GL\_DISPLAY} is
enabled, then the fully composited image is written back to the \OpenGL
frame buffer for display. It is the application's responsibility to
synchronize the processes and swap front and back buffers. The image
remaining in the frame buffer is undefined if \CEnum{ICET\_GL\_DISPLAY} is
disabled or the process is not displaying a tile.
If the \OpenGL background color is set to something other than black,
\CEnum{ICET\_GL\_DISPLAY\_COLORED\_BACKGROUND} should also be enabled.
Displaying with \CEnum{ICET\_GL\_DISPLAY\_COLORED\_BACKGROUND} disabled may
be slightly faster (depending on graphics hardware) but can result in black
rectangles in the background.
If \CEnum{ICET\_GL\_DISPLAY\_INFLATE} is enabled and the size of the
renderable window (determined by the current \OpenGL viewport) is greater
than that of the tile being displayed, then the image will first be
``inflated'' to the size of the actual display. If
\CEnum{ICET\_GL\_DISPLAY\_INFLATE} is disabled, the image is drawn at its
original resolution at the lower left corner of the display. More details
on image inflation are given in
Chapter~\ref{sec:Customizing_Compositing:Image_Inflation}.
Regardless of whether it writes the fully composited image back to the
display, \CFunc{icetGLDrawFrame} returns an \CType{IceTImage} containing
the composited image displayed on this process. If the process is not
displaying a tile, then the contents of the image is undefined.
\subsection{Rendering Without Callbacks}
\label{sec:Basic_Usage:Rendering:Without_Callbacks}
Sometimes it is inconvenient to structure an application such that it can
render images from within an \IceT callback. For this case, \IceT supports
a mechanism that allows rendering images completely independent of the
compositing done within the \IceT library. This is done by first rendering
images and then calling \CFunc{icetCompositeImage}.
\begin{Table}{3}
\multicolumn{3}{l}{
\CType{IceTImage}\textC{ }\CFunc{icetCompositeImage}\textC{(}
} \\
\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad
&\textC{const IceTVoid *}&\CArg{color\_buffer}\textC{,} \\
&\textC{const IceTVoid *}&\CArg{depth\_buffer}\textC{,} \\
&\textC{const IceTInt *}&\CArg{valid\_pixels\_viewport}\textC{,} \\
&\textC{const IceTDouble *}&\CArg{projection\_matrix}\textC{,} \\
&\textC{const IceTDouble *}&\CArg{modelview\_matrix}\textC{,} \\
&\textC{const IceTFloat *}&\CArg{background\_color}\quad\textC{);}
\end{Table}
The \CFunc{icetCompositeImage} function takes image buffer data and
composites it to a single image. This function behaves similarly to
\CFunc{icetDrawFrame} except that instead of using callback functions to
render and retrieve image data, the images are pre-rendered and passed
directly to \CFunc{icetCompositeImage}.
The \CArg{color\_buffer} and \CArg{depth\_buffer} arguments point to
memory buffers that contain the image data. The image data is always
stored in densely packed arrays in row-major order (a.k.a. x-major order
or by scan-lines). The first horizontal scan-line is at the bottom of the