ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgflib/mgfdoc.tr
Revision: 1.9
Committed: Wed Nov 22 12:23:27 1995 UTC (28 years, 5 months ago) by greg
Content type: application/x-troff
Branch: MAIN
Changes since 1.8: +5 -1 lines
Log Message:
made mgfilt expand included files for version conformancy

File Contents

# User Rev Content
1 greg 1.1 .\" SCCSid "$SunId$ LBL"
2     .nr PS 11
3     .ps 11
4     .nr VS 12
5     .vs 12
6     .nr PD .5v
7     .ds LF MGF
8     .ds RF Version 1.0
9     .DA May 1995
10     .TL
11     The Materials and Geometry Format
12     .AU
13     Greg Ward
14     .br
15     Lawrence Berkeley Laboratory
16     .NH
17     Introduction
18     .LP
19     The Materials and Geometry Format (referred to henceforth as MGF)
20     is a description language for 3-dimensional environments expressly
21     suited to visible light simulation and rendering.
22     The materials are physically-based and rely on standard and
23     well-accepted definitions of color, reflectance and transmittance
24     for good accuracy and reproducibility.
25     The geometry is based on boundary representation using simple
26     geometric primitives such as polygons, spheres and cones.
27     The file format itself is terse but human-readable ASCII text.
28     .NH 2
29     What makes MGF special?
30     .LP
31     There are three principal reasons to use MGF as an input language for
32     lighting simulation and physically-based rendering:
33     .RS
34     .IP 1.
35     It's the only existing format that describes materials physically.
36     .IP 2.
37     It is endorsed by the Illuminating Engineering Society of North
38     America (IESNA) as part of their LM-63-1995 standard for luminaire data.
39     .IP 3.
40     It's easy and fun to support since it comes with a standard parser
41     and sample scenes and objects at the web site,
42     "http://radsite.lbl.gov/mgf/HOME.html".
43     .RE
44     .LP
45     The standard parser provides both immediate and a long-term
46     benefits, since it presents a programming interface that is more
47     stable even than the language itself.
48     Unlike AutoCAD DXF and other de facto standards, a change to the
49     language will not break existing programs.
50     This is because the parser gives the calling software only those
51     entities it can handle.
52     If the translator understands only polygons, it will be given only
53     polygons.
54     If a new geometric primitive is included in a later version of the
55     standard, the new parser that comes with it will still be able to
56     express this entity as polygons.
57     Thus, the urgency of modifying code to support a changing standard
58     is removed, and long-term stability is assured.
59     .LP
60     This notion of
61     .I extensibility
62     is a cornerstone of the format, and it goes well beyond the
63     extensibility of other languages because is guarantees that new
64     versions of the standard will not break existing programs, and the
65     new information will be used as much as possible.
66     Other languages either require that all translators stay up to date
67     with the latest standard, or allow forward compatibility by simply
68     .I ignoring
69     new entities.
70     In MGF, if NURBS are added at some point and the translator or
71     loader does not handle them directly, the new version of the parser
72     will automatically convert them to smoothed polygons without
73     changing a single line of the calling program.
74     It is merely necessary to link to the new library, and all the new
75     entities are supported\(dg.
76     .FS
77     \(dgIf an old version of the parser encounters new entities it does
78     not recognize, the default action is to ignore them, printing a warning
79     message.
80     This may be overridden to support custom entities, but such
81     practice is discouraged because it weakens the standard.
82     .FE
83     .NH 2
84     What does MGF look like?
85     .LP
86     MGF has a simple entity-per-line structure, with a similar
87     appearance to Wavefront's .OBJ format.
88     Each entity is specified by a short keyword, and
89     arguments are separated by white space (tabs and/or spaces).
90     A newline may be escaped with a backslash ('\\'), in which case it
91     counts as a space.
92     Lines and continued lines may have up to 4096 characters, including
93     newlines, tabs and spaces.
94     A comment is an ignored entity whose keyword is the pound sign ('#').
95     .LP
96     Here is an MGF file that describes a simple two-drawer file cabinet:
97     .DS
98     # Conversion from inches to meters
99     xf -s .0254
100     # Surface material
101     m burgundy_formica =
102     c
103     cxy .362 .283
104     rd .0402
105     c
106     rs .0284 .05
107     sides 1
108     # Cabinet vertices
109     v fc.xy =
110     p .05 0 0
111     v fc.xY =
112     p .05 18 0
113     v fc.XY =
114     p 35.95 18 0
115     v fc.Xy =
116     p 35.95 0 0
117     # Cabinet
118     prism fc.xy fc.xY fc.XY fc.Xy 24
119     # Drawer vertices
120     v fcd.Xz =
121     p 34 0 0
122     v fcd.XZ =
123     p 34 0 10
124     v fcd.xZ =
125     p 0 0 10
126     v fcd.xz =
127     p 0 0 0
128     # Two drawers
129     o drawer
130     xf -t 1 18.1 2 -a 2 -t 0 0 11
131     prism fcd.xz fcd.Xz fcd.XZ fcd.xZ .9
132     xf
133     o
134     # End of units conversion
135     xf
136     .DE
137     .NH 2
138     MGF's place in the world of standards
139     .LP
140     MGF was developed initially to support detailed geometric
141     description of light fixtures for the IESNA luminaire data standard,
142     publication LM-63\(dg.
143     .FS
144     \(dgTo obtain the latest version of this standard, write to:
145     Illuminating Engineering Society of North America,
146     345 East 47th St.,
147     New York, NY 10017.
148     .FE
149     Existing standards for geometric description were either too
150     cumbersome (e.g.
151     .I Radiance)
152     or did not include physical materials (e.g. IGES).
153     It was noted early on that a standard able to fully describe
154     luminaires would necessarily be
155     capable of describing other objects as well; indeed whole
156     environments could be defined this way.
157     Since the descriptions would be physical, they could serve as input
158     to both lighting simulation and rendering software.
159     A standard language for describing the appearance of physical
160     objects has been lacking for some time, and current efforts in this
161     direction (i.e. STEP) seem several years away from fruition.
162     (There are other languages for describing realistic scenes
163     that deserve mention here, such as VRML and the Manchester Scene
164     Description Language, but none give specific attention to physical
165     material properties and are thus unsuitable for lighting
166     simulation.)\0
167     .LP
168     In short, we saw this as an opportunity to offer the lighting and
169     rendering community a simple and easy-to-support standard for
170     describing environments in a physically valid way.
171     Our hope is that this will promote sharing color, material and object
172     libraries as well as complete scene descriptions.
173     Sharing libraries is of obvious benefit to users and software
174     developers alike.
175     Sharing scenes should also permit
176     comparisons between rendering systems and
177     intervalidation of lighting calculations.
178     As anyone who works in this field knows, modeling is the most
179     difficult step in creating any simulation or rendering, and there is
180     no excuse for this data being held prisoner by a proprietary data
181     format.
182     .NH
183     MGF Basics
184     .LP
185     The default coordinate system in MGF is right-handed with
186     distances given in meters, though this can be effectively changed
187     by specifying a global transformation.
188     The transformation context is affected by the
189     .UL xf
190     entity, and the whole of MGF can be understood in terms of entities
191     and contexts.
192     .NH 2
193     Entities and Contexts
194     .LP
195     An
196     .I entity
197     in MGF is any non-blank line, which must be one of a finite set of
198     command keywords followed by zero or more arguments.
199     (As mentioned previously, an entity may continue over multiple lines
200     by escaping the newline with a backslash.)\0
201     Table 1 gives a list of entities and their expected arguments.
202     Section 3 gives more detailed information on each entity.
203     .KF
204     .TS
205     expand, box;
206     l l l.
207     Keyword Arguments Interpretation
208     = = =
209     # [anything ...] a comment
210     o [name] begin/end object context
211     xf [xform] begin/end transformation context
212     i pathname [xform] include file (with transformation)
213     ies pathname [-m f][xform] include IES luminaire (with transformation)
214     _ _ _
215     c [id [= [template]]] get/set color context
216     cxy x y set CIE (x,y) chromaticity for current color
217     cspec l_min l_max v1 v2 ... set relative spectrum for current color
218     cct temperature set spectrum based on black body temperature
219     cmix w1 c1 w2 c2 ... mix named colors to make current color
220     _ _ _
221     m [id [= [template]]] get/set material context
222     sides {1|2} set number of sides for current material
223     rd rho_d set diffuse reflectance for current material
224     td tau_d set diffuse transmittance for current material
225     ed epsilon_d set diffuse emittance for current material
226     rs rho_s alpha_r set specular reflectance for current material
227     ts tau_s alpha_t set specular transmittance for current material
228     ir n_real n_imag set index of refraction for current material
229     _ _ _
230     v [id [= [template]]] get/set vertex context
231     p x y z set point position for current vertex
232     n dx dy dz set surface normal for current vertex
233     _ _ _
234     f v1 v2 v3 ... polygon using current material, spec. vertices
235     sph vc radius sphere
236     cyl v1 radius v2 truncated right cylinder (open-ended)
237     cone v1 rad1 v2 rad2 truncated right cone (open-ended)
238     prism v1 v2 v3 ... length truncated right prism (closed solid)
239     ring vc rmin rmax circular ring with inner and outer radii
240     torus vc rmin rmax circular torus with inner and outer radii
241     .TE
242     .QP
243     .B "Table 1".
244     MGF entities and their arguments.
245     Arguments in brackets are optional.
246     Arguments in curly braces mean one of the given choices must
247     appear.
248     Ellipsis (...) mean that any number of arguments may be given.
249     .sp
250     .KE
251     .LP
252     A
253     .I context
254     describes the current state of the interpreter, and affects or is
255     affected by certain entities as they are read in.
256     MGF contexts can be divided into two types,
257     .I "hierarchical contexts"
258     and
259     .I "named contexts".
260     .LP
261     Hierarchical contexts are manipulated by a single entity and
262     have an associated "stack" onto which new
263     contexts are "pushed" using the entity.
264     The last context may be "popped" by giving the entity again with no
265     arguments.
266     The two hierarchical contexts in MGF are the current transformation,
267     manipulated with the
268     .UL xf
269     entity, and the current object, manipulated with the
270     .UL o
271     entity.
272     .KF
273     .TS
274     expand, allbox;
275     l c l l l.
276     Context Cntl. Entity Default Value Field Entities Affects
277     = = = = =
278     Object o - - -
279     Transform xf - - T{
280     f, sph, cyl, cone,
281     ring, torus, prism
282     T}
283     Material m 2-sided black T{
284     sides, rd, td,
285     ed, rs, ts
286     T} T{
287     f, sph, cyl, cone,
288     ring, torus, prism
289     T}
290     Color c neutral grey T{
291     cxy, cspec, cct, cmix
292     T} T{
293     rd, td, ed, rs, ts
294     T}
295     Vertex v T{
296     (0,0,0),
297     no normal
298     T} p, n T{
299     f, sph, cyl, cone,
300     ring, torus, prism
301     T}
302     .TE
303     .QP
304     .B "Table 2".
305     MGF contexts and their related entities and default values.
306     .sp
307     .KE
308     .LP
309     Named contexts in contrast hold sets of values that are swapped
310     in and out one at a time.
311     There are three named contexts in MGF, the current material, the
312     current color and the current vertex.
313     Each one may be associated with an identifier (any non-white
314     sequence of printing ASCII characters beginning with a letter),
315     and one of each is in effect at any given time.
316     Initially, these contexts are unnamed, and invoking an unnamed
317     context always returns to the original (default) values.
318     (See Table 2 for a list of contexts, their related
319     entities and defaults.)\0
320     .LP
321     It is easiest to think of a context as a "scratch space" where
322     values are written by some entities and read by others.
323     Naming a context allows us to reestablish the same scratch space
324     later, usually for reference but it can be altered as well.
325     Let us say we wanted to create a smooth blue plastic material with a
326     diffuse reflectance of 20% and a specular reflectance of 4%:
327     .DS
328     # Establish a new material context called "blue_plastic"
329     m blue_plastic =
330     # Reestablish a previous color context called "blue"
331     c blue
332     # Set the diffuse reflectance, which uses the above color
333     rd .20
334     # Get the unnamed color context (always starts out grey)
335     c
336     # Set the specular reflectance, which is uncolored
337     rs .04 0
338     # We're done, the current material context is now "blue_plastic"
339     .DE
340     Note that the above assumes that we have previously defined a color
341     context named "blue".
342     If we forgot to do that, the above description would generate an
343     "undefined" error.
344     The color context affects the material context indirectly because it
345     is read by the specular and diffuse reflectance entities, which are
346     in turn written to the current material.
347     It is not necessary to indent the entities that affect the material
348     definition, but it improves readability.
349     Note also that there is no explicit end to the material definition.
350     As long as a context remains in effect, its contents may be altered
351     by its field entities.
352     This will not affect previous uses of the context, however.
353     For example, a surface entity following the above definition will
354     have the specified color and reflectance, and later changes to the
355     material "blue_plastic" will have no effect on it.
356     .LP
357     Each of the three named contexts has an associated entity that
358     controls it.
359     The material context is controlled by the
360     .UL m
361     entity, the color context is controlled by the
362     .UL c
363     entity, and the vertex context is controlled by the
364     .UL v
365     entity.
366     There are exactly four forms for each entity.
367     The first form is the keyword by itself, which establishes
368     an unnamed context with predetermined default values.
369     This is a useful way to set values without worrying about saving
370     them for recall later.
371     The second form is to give the keyword with a previously defined
372     name.
373     This reestablishes a prior context for reuse.
374     The third form is to give the keyword with a name followed by an
375     equals sign.
376     (There must be a space between the name and the equals sign, since
377     it is a separate argument.)\0
378     This establishes a new context and assigns it the same default
379     values as the unnamed context.
380     The fourth and final form gives the keyword followed by a name then
381     an equals then the name of a previous context definition.
382     This establishes a new context for the first name, assigning the
383     values from the second named context rather than the usual defaults.
384     This is a convenient way create an alias or
385     to modify a context under a new name (i.e. "save as").
386     .NH 2
387     Hierarchical Contexts and Transformations
388     .LP
389     As mentioned in the last subsection, there are two hierarchical
390     contexts in MGF, the current object and the current transformation.
391     We will start by discussing the current object, since it is
392     the simpler of the two.
393     .NH 3
394     Objects
395     .LP
396     There is no particular need in lighting simulation or rendering to
397     name objects, but it may help the user
398     to know what object a particular surface is associated with.
399     The
400     .UL o
401     entity provides a convenient mechanism for associating names with
402     surfaces.
403     The basic use of this entity is as follows:
404     .DS
405     o object_name
406     [object entities...]
407     o subobject_name
408     [subobject entities...]
409     o
410     [more object entities and subobjects...]
411     o
412     .DE
413     The
414     .UL o
415     keyword by itself marks the end of an object context.
416     Any number of hierarchical context levels are supported, and there are no
417     rules governing the choice of object names except that they begin
418     with a letter and be made up of printing, non-white ASCII characters.
419     Indentation is not necessary of course, but it does improve
420     readability.
421     .NH 3
422     Transformations
423     .LP
424     MGF supports only rigid-body (i.e. non-distorting) transformations
425     with uniform scaling.
426     Unlike the other contexts, transformations have no associated
427     name, only arguments.
428     Thus, there is no way to reestablish a previous transformation other
429     than to give the same arguments over again.
430     Since the arguments are concise and self-explanatory, this was thought
431     sufficient.
432     The following transformation flags and
433     parameters are defined:
434 greg 1.2 .TS
435     center;
436 greg 1.1 l l.
437     -t dx dy dz translate objects along the given vector
438     -rx degrees rotate objects about the X-axis
439     -ry degrees rotate objects about the Y-axis
440     -rz degrees rotate objects about the Z-axis
441     -s scalefactor scale objects by the given factor
442     -mx mirror objects about the Y-Z plane
443     -my mirror objects about the X-Z plane
444     -mz mirror objects about the X-Y plane
445     -i N repeat the following arguments N times
446     -a N make an array of N geometric instances
447     .TE
448     Transform arguments have a cumulative effect.
449     That is, a rotation
450     about X of 20 degrees followed by a rotation about X of -50 degrees
451     results in a total rotation of -30 degrees.
452     However, if the two
453     rotations are separated by some translation vector, the cumulative
454     effect is quite different.
455     It is best to think of each argument as
456     acting on the included geometric objects, and each subsequent transformation
457     argument affects the objects relative to their new position/orientation.
458     .LP
459     For example, rotating an object about its center is most easily done
460     by translating
461     the object back to the origin, applying the desired rotation, and translating
462     it again back to its original position, like so:
463     .DS
464     # rotate an included object 20 degrees clockwise looking down
465     # an axis parallel to Y and passing through the point (15,0,-35)
466     xf -t -15 0 35 -ry -20 -t 15 0 -35
467     i object.mgf
468     xf
469     .DE
470     Note that the include entity,
471     .UL i,
472     permits a transformation to be given with it, so the above could
473     have been written more compactly as:
474     .DS
475     i object.mgf -t -15 0 35 -ry -20 -t 15 0 -35
476     .DE
477     .LP
478     Rotations are given in degrees counter-clockwise about a principal axis.
479     That is, with the thumb of the right hand pointing in the direction
480     of the axis, rotation follows the curl of the fingers.
481     .LP
482     The transform entity itself is cumulative, but in the reverse
483     order to its arguments.
484     That is, later transformations (i.e. enclosed transformations)
485     are prepended to existing (i.e. enclosing) ones.
486     A transform command
487     with no arguments is used to return to the previous condition.
488     It is
489     necessary that transforms and their end statements ("xf" by itself) be
490     balanced in a file, so that later or enclosing files are not affected.
491     .LP
492     Transformations apply only to geometric types, e.g. polygons, spheres, etc.
493     Vertices and the components that go into geometry are not directly affected.
494     This is to avoid confusion and the inadvertent multiple application of a
495     given transformation.
496     For example:
497     .DS
498     xf -t 5 0 0
499     v v1 =
500     p 0 10 0
501     n 0 0 1
502     xf -rx 180
503     # Transform now in effect is "-rx 180 -t 5 0 0"
504     ring v1 0 2
505     xf
506     xf
507     .DE
508     The final ring center is (5,-10,0) -- note that the vertex itself is
509     not affected by the transformation, only the geometry that calls on
510     it.
511     The normal orientation is (0,0,-1) due to the rotation about X,
512     which also reversed the sign of the central Y coordinate.
513     .NH 3
514     Arrays
515     .LP
516     The -a N transform specification causes the following transform
517     arguments to be repeated along with the contents of the included
518     objects N times.
519     The first instance of the geometry will be in its
520     initial location; the second instance will be repositioned according
521     to the named transformation; the third instance will be repositioned by
522     applying this transformation twice, and so on up to N-1 applications.
523     .LP
524     Multi-dimensional arrays may be specified with a single include
525     entity by giving multiple array commands separated by their
526     corresponding transforms.
527     A final transformation may be given
528     by preceding it with a -i 1 specification.
529     In other words, the
530     scope of an array command continues until the next -i or -a option.
531     .LP
532     The following MGF description places 60 spheres at a one unit spacing
533     in a 3x4x5 array, then moves the whole thing to an origin of
534     (15,30,45):
535     .DS
536     v v0 =
537     p 0 0 0
538     xf -a 3 -t 1 0 0 -a 4 -t 0 1 0 -a 5 -t 0 0 1 -i 1 -t 15 30 45
539     sph v0 0.1
540     xf
541     .DE
542     Note the "-i 1" in the specification, which marks the end of the
543     third array arguments before the final translation.
544     .NH 2
545     Detailed MGF Example
546     .LP
547     The following example of a simple room with a single door
548     and six file cabinets shows MGF in action, with copious comments to
549     help explain what's going on.
550 greg 1.2 .LP
551 greg 1.1 .DS
552     # "ceiling_tile" is a diffuse white surface with 75% reflectance:
553     # Create new named material context and clear it
554     m ceiling_tile =
555     # Specify one-sided material so we can see through from above
556     sides 1
557     # Set neutral color
558     c
559     # Set diffuse reflectance
560     rd .75
561     # "stainless_steel" is a mostly specular surface with 70% reflectance:
562     m stainless_steel =
563     sides 1
564     c
565     # Set specular reflectance to 50%, .08 roughness
566     rs .5 .08
567     # Other 20% reflectance is diffuse
568     rd .2
569    
570     # The following materials were measured with a spectrophotometer:
571     m beige_paint =
572     sides 1
573     # Set diffuse spectral reflectance
574     c
575     # Spectrum measured in 10 nm increments from 400 to 700 nm
576     cspec 400 700 35.29 44.87 47.25 47.03 46.87 47.00 47.09 \\\\
577     47.15 46.80 46.17 46.26 48.74 51.08 51.31 51.10 \\\\
578     51.11 50.52 50.36 51.72 53.61 53.95 52.08 49.49 \\\\
579     48.30 48.75 49.99 51.35 52.75 54.44 56.34 58.00
580     rd 0.5078
581     # Neutral (grey) specular component
582     c
583     rs 0.0099 0.08000
584     m mottled_carpet =
585     sides 1
586     c
587     cspec 400 700 11.23 11.28 11.39 11.49 11.61 11.73 11.88 \\\\
588     12.02 12.12 12.19 12.30 12.37 12.37 12.36 12.34 \\\\
589     12.28 12.22 12.29 12.45 12.59 12.70 12.77 12.82 \\\\
590     12.88 12.98 13.24 13.67 14.31 15.55 17.46 19.75
591     rd 0.1245
592     m reddish_cloth =
593     # 2-sided so we can observe it from behind
594     sides 2
595     c
596     cspec 400 700 28.62 27.96 27.86 28.28 29.28 30.49 31.61 \\\\
597     32.27 32.26 31.83 31.13 30.07 29.14 29.03 29.69 \\\\
598     30.79 32.30 33.90 34.56 34.32 33.85 33.51 33.30 \\\\
599     33.43 34.06 35.26 37.04 39.41 42.55 46.46 51.00
600     rd 0.3210
601     m burgundy_formica =
602     sides 1
603     c
604     cspec 400 700 3.86 3.74 3.63 3.51 3.34 3.21 3.14 \\\\
605     3.09 3.08 3.14 3.13 2.91 2.72 2.74 2.72 \\\\
606     2.60 2.68 3.40 4.76 6.05 6.65 6.75 6.68 \\\\
607     6.63 6.56 6.51 6.46 6.41 6.36 6.34 6.34
608     rd 0.0402
609     c
610     rs 0.0284 0.05000
611     m speckled_grey_formica =
612     sides 1
613     c
614     cspec 400 700 30.95 44.77 51.15 52.60 53.00 53.37 53.68 \\\\
615     54.07 54.33 54.57 54.85 55.20 55.42 55.51 55.54 \\\\
616     55.46 55.33 55.30 55.52 55.81 55.91 55.92 56.00 \\\\
617     56.22 56.45 56.66 56.72 56.58 56.44 56.39 56.39
618     rd 0.5550
619     c
620     rs 0.0149 0.15000
621    
622     # 40' x 22' x 9' office space with no windows and one door
623    
624     # All measurements are in inches, so enclose with a metric conversion:
625     xf -s .0254
626    
627     # The room corner vertices:
628     v rc.xyz =
629     p 0 0 0
630     v rc.Xyz =
631     p 480 0 0
632     v rc.xYz =
633     p 0 264 0
634     v rc.xyZ =
635     p 0 0 108
636     v rc.XYz =
637     p 480 264 0
638     v rc.xYZ =
639     p 0 264 108
640     v rc.XyZ =
641     p 480 0 108
642     v rc.XYZ =
643     p 480 264 108
644    
645     # The floor:
646     # Push object name
647     o floor
648     # Get previously defined carpet material
649     m mottled_carpet
650     # Polygonal face using defined vertices
651     f rc.xyz rc.Xyz rc.XYz rc.xYz
652     # Pop object name
653     o
654    
655     # The ceiling:
656     o ceiling
657     m ceiling_tile
658     f rc.xyZ rc.xYZ rc.XYZ rc.XyZ
659     o
660    
661     # The door outline vertices:
662     v do.xz =
663     p 216 0 0
664     v do.Xz =
665     p 264 0 0
666     v do.xZ =
667     p 216 0 84
668     v do.XZ =
669     p 264 0 84
670    
671     # The walls:
672     o wall
673     m beige_paint
674     o x
675     f rc.xyz rc.xYz rc.xYZ rc.xyZ
676     o
677     o X
678     f rc.Xyz rc.XyZ rc.XYZ rc.XYz
679     o
680     o y
681     f rc.xyz rc.xyZ rc.XyZ rc.Xyz do.Xz do.XZ do.xZ do.xz
682     o
683     o Y
684     f rc.xYz rc.XYz rc.XYZ rc.xYZ
685     o
686     o
687    
688     # The door and jam vertices:
689     v djo.xz =
690     p 216 .5 0
691     v djo.xZ =
692     p 216 .5 84
693     v djo.XZ =
694     p 264 .5 84
695     v djo.Xz =
696     p 264 .5 0
697     v dji.Xz =
698     p 262 .5 0
699     v dji.XZ =
700     p 262 .5 82
701     v dji.xZ =
702     p 218 .5 82
703     v dji.xz =
704     p 218 .5 0
705     v door.xz =
706     p 218 0 0
707     v door.xZ =
708     p 218 0 82
709     v door.XZ =
710     p 262 0 82
711     v door.Xz =
712     p 262 0 0
713    
714     # The door, jam and knob
715     o door
716     m burgundy_formica
717     f door.xz door.xZ door.XZ door.Xz
718     o jam
719     m beige_paint
720     f djo.xz djo.xZ djo.XZ djo.Xz dji.Xz dji.XZ dji.xZ dji.xz
721     f djo.xz do.xz do.xZ djo.xZ
722     f djo.xZ do.xZ do.XZ djo.XZ
723     f djo.Xz djo.XZ do.XZ do.Xz
724     f dji.xz dji.xZ door.xZ door.xz
725     f dji.xZ dji.XZ door.XZ door.xZ
726     f dji.Xz door.Xz door.XZ dji.XZ
727     o
728     o knob
729     m stainless_steel
730     # Define vertices needed for curved geometry
731     v kb1 =
732     p 257 0 36
733     v kb2 =
734     p 257 .25 36
735     n 0 1 0
736     v kb3 =
737     p 257 2 36
738     # 1" diameter cylindrical base from kb1 to kb2
739     cyl kb1 1 kb2
740     # Ring at base of knob stem
741     ring kb2 .4 1
742     # Knob stem
743     cyl kb2 .4 kb3
744     # Spherical knob
745     sph kb3 .85
746     o
747     o
748    
749     # Six file cabinets (36" wide each)
750     # ("filecab.inc" was given as an earlier example in Section 1.2)
751     o filecab.x
752     # include a file as an array of three 36" apart
753     i filecab.inc -t -36 0 0 -rz -90 -t 1 54 0 -a 3 -t 0 36 0
754     o
755     o filecab.X
756     # the other three cabinets
757     i filecab.inc -rz 90 -t 479 54 0 -a 3 -t 0 36 0
758     o
759    
760     # End of transform from inches to meters:
761     xf
762    
763     # The 10 recessed fluorescent ceiling fixtures
764     ies hlrs2gna.ies -t 1.2192 2.1336 2.74 -a 5 -t 2.4384 0 0 -a 2 -t 0 2.4384 0
765     .DE
766     .bp
767     .NH
768     MGF Entity Reference
769     .LP
770     There are currently 28 entities in the MGF specification.
771     For ease of reference we have broken these into five categories:
772     .IP 1.
773     General
774 greg 1.2 .TS
775 greg 1.1 lw(.75i) lw(1.75i) lw(3i).
776     # [anything ...] a comment
777     o [name] begin/end object context
778     xf [xform] begin/end transformation context
779     i pathname [xform] include file (with transformation)
780     ies pathname [-m f][xform] include IES luminaire (with transformation)
781     .TE
782     .IP 2.
783     Color
784 greg 1.2 .TS
785 greg 1.1 lw(.75i) lw(1.75i) lw(3i).
786     c [id [= [template]]] get/set color context
787     cxy x y set CIE (x,y) chromaticity for current color
788     cspec l_min l_max v1 v2 ... set relative spectrum for current color
789     cct temperature set spectrum based on black body temperature
790     cmix w1 c1 w2 c2 ... mix named colors to make current color
791     .TE
792     .IP 3.
793     Material
794     .TS
795     lw(.75i) lw(1.75i) lw(3i).
796     m [id [= [template]]] get/set material context
797     sides {1|2} set number of sides for current material
798     rd rho_d set diffuse reflectance for current material
799     td tau_d set diffuse transmittance for current material
800     ed epsilon_d set diffuse emittance for current material
801     rs rho_s alpha_r set specular reflectance for current material
802     ts tau_s alpha_t set specular transmittance for current material
803     ir n_real n_imag set index of refraction for current material
804     .TE
805     .IP 4.
806     Vertex
807     .TS
808     lw(.75i) lw(1.75i) lw(3i).
809     v [id [= [template]]] get/set vertex context
810     p x y z set point position for current vertex
811     n dx dy dz set surface normal for current vertex
812     .TE
813     .IP 5.
814     Geometry
815     .TS
816     lw(.75i) lw(1.75i) lw(3i).
817     f v1 v2 v3 ... polygon using current material, spec. vertices
818     sph vc radius sphere
819     cyl v1 radius v2 truncated right cylinder (open-ended)
820     cone v1 rad1 v2 rad2 truncated right cone (open-ended)
821     prism v1 v2 v3 ... length truncated right prism (closed solid)
822     ring vc rmin rmax circular ring with inner and outer radii
823     torus vc rmin rmax circular torus with inner and outer radii
824     .TE
825     .ds LH General Entities
826     .ds RH #
827     .bp
828     .SH
829     NAME
830     .LP
831     # - a comment
832     .SH
833     SYNOPSIS
834     .LP
835     .B #
836     [
837     .I anything
838     ]
839     .SH
840     DESCRIPTION
841     .LP
842     A comment is a bit of text explanation.
843     Since it is an entity like any other (except that it has no effect),
844     there must be at least one space between the keyword (which is a
845     pound sign) and the "arguments," and the end of line may be escaped
846     as usual with the backslash character ('\\').
847     .LP
848     A comment may actually be used to hold auxiliary information such as
849     view parameters, which may be interpreted by some destination program.
850     Care should be taken under such circumstances that the user does not
851     inadvertently mung or mimic this information in other comments, and
852     it is therefore advisable to use an additional set of identifying
853     characters to distinguish such data.
854     .SH
855     EXAMPLE
856     .DS
857     # The following include file is in inches, so convert to meters
858     i cubgeom.inc -s .0254
859     # Stuff we don't want to see at the moment:
860     # i person.mgf -t 3 2 0
861     # ies hlrs3gna.ies -rz 90 -t 1.524 1.8288 2.74 \\\\
862     -a 6 -t 1.8288 0 0 -a 2 -t 0 3.048 0
863     .DE
864     .ds RH O
865     .bp
866     .SH
867     NAME
868     .LP
869     o - begin or end object context
870     .SH
871     SYNOPSIS
872     .LP
873     .B o
874     [
875     .I name
876     ]
877     .SH
878     DESCRIPTION
879     .LP
880     If
881     .I name
882     is given, we push a new object context onto the stack, which is to
883     say that we begin a new subobject by this name\(dg.
884     .FS
885     \(dgA name is any sequence of printing, non-white ASCII characters
886     beginning with a letter.
887     .FE
888     If the
889     .UL o
890     keyword is given by itself, then we pop the last object context off
891     the stack, which means that we leave the current subobject.
892     .LP
893     All geometry between the start of an object context and its matching
894     end statement is associated with the given name.
895     This may be used in modeling software to help identify objects and
896     subobjects, or it may be ignored altogether.
897     .LP
898     Object begin and end statements should be balanced in a file, and
899     care should be taken not to overlap transform
900     .UL (xf)
901     contexts with object contexts, especially when arrays are involved.
902     This is because the standard parser will assign object contexts to
903     instanced geometry, which can get confused with other object
904     contexts if a clear enclosure is not maintained.
905     .SH
906     EXAMPLE
907     .DS
908     o body
909     o torso
910     i torso.mgf
911     o
912     o arm
913     o left
914     i leftarm.mgf
915     o
916     o right
917     i leftarm.mgf -mx
918     o
919     o
920     o
921     .DE
922     .SH
923     SEE ALSO
924     .LP
925     .UL xf
926     .ds RH XF
927     .bp
928     .SH
929     NAME
930     .LP
931     xf - begin or end transformation context
932     .SH
933     SYNOPSIS
934     .LP
935     .B xf
936     [
937     .I transform
938     ]
939     .SH
940     DESCRIPTION
941     .LP
942     If a set of
943     .I transform
944     arguments are given, we push a new transformation context onto the
945     stack.
946     If the
947     .UL xf
948     keyword is given by itself, then we pop the last transformation
949     context off the stack.
950     The total transformation in effect at any given time is
951     computed by prepending each set subcontext arguments onto those of
952     its enclosing context.
953     This and other details about transformation specifications
954     are explained in some detail in section 2.2.2.
955     .LP
956     The following transformation flags and
957     parameters are defined:
958     .TS
959     center;
960     l l.
961     -t dx dy dz translate objects along the given vector
962     -rx degrees rotate objects about the X-axis
963     -ry degrees rotate objects about the Y-axis
964     -rz degrees rotate objects about the Z-axis
965     -s scalefactor scale objects by the given factor
966     -mx mirror objects about the Y-Z plane
967     -my mirror objects about the X-Z plane
968     -mz mirror objects about the X-Y plane
969     -i N repeat the following arguments N times
970     -a N make an array of N geometric instances
971     .TE
972     .SH
973     EXAMPLE
974     .DS
975     # Create 3x5 array of evenly-spaced spheres (grid size = 3)
976     v vc =
977     p 0 0 0
978     xf -t 1 1 10 -a 3 -t 3 0 0 -a 5 -t 0 3 0
979     sph vc .5
980     xf
981     .DE
982     .SH
983     SEE ALSO
984     .LP
985     .UL i,
986     .UL ies,
987     .UL o
988     .ds RH I
989     .bp
990     .SH
991     NAME
992     .LP
993     i - include MGF data file
994     .SH
995     SYNOPSIS
996     .LP
997     .B i
998     .I pathname
999     [
1000     .I transform
1001     ]
1002     .SH
1003     DESCRIPTION
1004     .LP
1005     Include the information contained in the file
1006     .I pathname.
1007     If a
1008     .I transform
1009     specification is given, then it will be applied as though the
1010     include statement were enclosed by beginning and ending
1011     .UL xf
1012     entities with this transformation.
1013     .LP
1014     The
1015     .I pathname
1016     will be interpreted relative to the enclosing MGF file.
1017     That is, if the file containing the include statement is in some
1018     parent or subdirectory, then the given pathname is appended to this
1019     directory.
1020     It is illegal to specify a
1021     .I pathname
1022     relative to the root directory, and the MGF standard requires that
1023     all filenames adhere to the ISO-9660 8.3 name format for maximum
1024     portability between systems.
1025     The directory separator is defined to be slash ('/'), and drive
1026     specifications (such as "c:") are not allowed.
1027     All pathnames should be given in lower case, and will be converted to
1028     upper case on systems that require it.
1029     (That way, there are no accidental name collisions.)\0
1030     .LP
1031     The suggested suffix for MGF-adherent files is ".mgf".
1032     Files that are not in metric units but are in MGF may be given any
1033     suffix, but we suggest using ".inc" as a convention.
1034     .SH
1035     EXAMPLE
1036     .DS
1037     # Define vertices for 62x30" partition
1038     i pv62x30.inc
1039     # Insert 2 62x30" partitions
1040     o cpart1
1041     i partn.inc -t 75 130.5 0
1042     o
1043     o cpart3
1044     i partn.inc -t 186 130.5 0
1045     o
1046     # Define vertices for 62x36" partition
1047     i pv62x36.inc
1048     # Insert 62x36" partition
1049     o cpart2
1050     i partn.inc -t 105 130.5 0
1051     o
1052     .DE
1053     .SH
1054     SEE ALSO
1055     .LP
1056     .UL ies,
1057     .UL o,
1058     .UL xf
1059     .ds RH IES
1060     .bp
1061     .SH
1062     NAME
1063     .LP
1064     ies - include IESNA luminaire file
1065     .SH
1066     SYNOPSIS
1067     .LP
1068     .B ies
1069     .I pathname
1070     [
1071     .B \-m
1072     .I multiplier
1073     ]
1074     [
1075     .I transform
1076     ]
1077     .SH
1078     DESCRIPTION
1079     .LP
1080     Load the IES standard luminaire information contained in the file
1081     .I pathname.
1082     If a
1083     .I multiplier
1084     is given, all candela values will be multiplied by this factor.
1085     (This option must appear first if present.)\0
1086     If a
1087     .I transform
1088     specification is given, then it will be applied as though the
1089     statement were enclosed by beginning and ending
1090     .UL xf
1091     entities with this transformation.
1092     .LP
1093     The
1094     .I pathname
1095     will be interpreted relative to the enclosing MGF file, and all
1096     restrictions discussed under the
1097     .UL i
1098     entity also apply to the IES file name.
1099     The suggested suffix is ".ies", but this has not been followed
1100     consistently by lighting manufacturers.
1101     .SH
1102     EXAMPLE
1103     .DS
1104     # Insert 10 2x4' fluorescent troffers in two groups
1105     ies cf9pr240.ies -t 3.6576 2.1336 2.74 -a 3 -t 2.4384 0 0 -a 2 -t 0 2.4384 0
1106     ies cf9pr240.ies -rz 90 -t 1.2192 1.8288 2.74 \\\\
1107     -a 2 -t 9.7536 0 0 -a 2 -t 0 3.048 0
1108     .DE
1109     .SH
1110     SEE ALSO
1111     .LP
1112     .UL i,
1113     .UL o,
1114     .UL xf
1115     .ds LH Color Entities
1116     .ds RH C
1117     .bp
1118     .SH
1119     NAME
1120     .LP
1121     c - get or set the current color context
1122     .SH
1123     SYNOPSIS
1124     .LP
1125     .B c
1126     [
1127     .I id
1128     [
1129     .B =
1130     [
1131     .I template
1132     ]
1133     ]
1134     ]
1135     .SH
1136     DESCRIPTION
1137     .LP
1138     If the
1139     .UL c
1140     keyword is given by itself, then it establishes the unnamed color
1141     context, which is neutral (i.e. equal-energy) grey.
1142     This context may be modified, but the changes will not be saved.
1143     .LP
1144     If the keyword is followed by an identifier
1145     .I id,
1146     then it reestablishes a previous context.
1147     If the specified context was never defined, an error will result.
1148     .LP
1149     If the entity is given with an identifier
1150     followed by an equals sign ('='), then a new context is established,
1151     and cleared to the default neutral grey.
1152     (Note that the equals sign must be separated from other
1153     arguments by white space to be properly recognized.)\0
1154     If the equals sign is followed by a second identifier
1155     .I template,
1156     then this previously defined color will be used as a source of
1157     default values rather than grey.
1158     This is most useful for establishing a color alias.
1159     .SH
1160     EXAMPLE
1161     .DS
1162     # Define the color "red32"
1163     c red32 =
1164     cxy .42 .15
1165     # Make "cabinet_color" an alias for "red32"
1166     c cabinet_color = red32
1167    
1168     # Later in another part of the description...
1169    
1170     # Get our cabinet color
1171     c cabinet_color
1172     # Get the geometry
1173     i cabgeom.mgf
1174     .DE
1175     .SH
1176     SEE ALSO
1177     .LP
1178     .UL cct,
1179     .UL cmix,
1180     .UL cspec,
1181     .UL cxy,
1182     .UL m
1183     .ds RH CXY
1184     .bp
1185     .SH
1186     NAME
1187     .LP
1188     cxy - set the CIE (x,y) chromaticity for the current color
1189     .SH
1190     SYNOPSIS
1191     .LP
1192     .B cxy
1193     .I "x y"
1194     .SH
1195     DESCRIPTION
1196     .LP
1197     This entity sets the current color using (x,y) chromaticity
1198     coordinates for the 1931 CIE standard 2 degree observer.
1199     Legal values for
1200     .I x
1201     and
1202     .I y
1203     are greater than zero and sum to less than one, and more
1204     specifically they must fit within the curve of the visible spectrum.
1205     The
1206     .I x
1207     coordinate roughly corresponds to the red part of the spectrum and
1208     the
1209     .I y
1210     coordinate corresponds to the green.
1211     The CIE z coordinate is implicit, since it is equal to (1-x-y).
1212     .LP
1213     All colors in MGF are absolute, thus colorimeter measurements should
1214     be conducted the same for surfaces as for light sources.
1215     Applying a standard illuminant calculation is redundant and
1216     introduces inaccuracies, and should therefore be avoided if
1217     possible.
1218     .LP
1219     Conversion between CIE colors and those more commonly used in
1220     computer graphics are described in the application notes section
1221     6.1.1.
1222     .SH
1223     EXAMPLE
1224     .DS
1225     # Set unnamed color context
1226     c
1227     # Set CIE chromaticity to a bluish hue
1228     cxy .15 .2
1229     # Apply color to diffuse reflectance of 15%
1230     rd .15
1231     .DE
1232     .SH
1233     SEE ALSO
1234     .LP
1235     .UL c,
1236     .UL cct,
1237     .UL cmix,
1238     .UL cspec
1239     .ds RH CSPEC
1240     .bp
1241     .SH
1242     NAME
1243     .LP
1244     cspec - set the relative spectrum for the current color
1245     .SH
1246     SYNOPSIS
1247     .LP
1248     .B cspec
1249     .I "l_min l_max o1 o2 ... oN"
1250     .SH
1251     DESCRIPTION
1252     .LP
1253     Assign a relative spectrum measured between
1254     .I l_min
1255     and
1256     .I l_max
1257     nanometers at evenly spaced intervals.
1258     The first value,
1259     .I o1
1260     corresponds to the measurement at
1261     .I l_min,
1262     and the last value,
1263     .I oN
1264     corresponds to the measurement at
1265     .I l_max.
1266     Values in between are separated by
1267     .I "(l_max-l_min)/(N-1)"
1268     nanometers.
1269 greg 1.6 All values should be non-negative unless defining a component for
1270     complementary color mixing, and the spectrum outside of the
1271 greg 1.1 specified range is assumed to be zero.
1272     (The visible range is 380 to 780 nm.)\0
1273     The actual units and scale of the measurements do not matter,
1274     since the total will be
1275     normalized according to whatever the color is modifying
1276     (e.g. photometric reflectance or emittance).
1277     .SH
1278     EXAMPLE
1279     .DS
1280     # Color measured at 10 nm increments from 400 to 700
1281     m reddish_cloth =
1282     c
1283     cspec 400 700 28.62 27.96 27.86 28.28 29.28 30.49 31.61 \\\\
1284     32.27 32.26 31.83 31.13 30.07 29.14 29.03 29.69 \\\\
1285     30.79 32.30 33.90 34.56 34.32 33.85 33.51 33.30 \\\\
1286     33.43 34.06 35.26 37.04 39.41 42.55 46.46 51.00
1287     rd 0.3210
1288     .DE
1289     .SH
1290     SEE ALSO
1291     .LP
1292     .UL c,
1293     .UL cct,
1294     .UL cmix,
1295     .UL cxy
1296     .ds RH CCT
1297     .bp
1298     .SH
1299     NAME
1300     .LP
1301     cct - set the current color to a black body spectrum
1302     .SH
1303     SYNOPSIS
1304     .LP
1305     .B cct
1306     .I temperature
1307     .SH
1308     DESCRIPTION
1309     .LP
1310     The
1311     .UL cct
1312     entity sets the current color to the spectrum of an ideal
1313     black body radiating at
1314     .I temperature
1315     degrees Kelvin.
1316     This is often the most convenient way to set the color of an
1317     incandescent light source, but it is not recommended for
1318     fluorescent lamps or other materials that do not fit a
1319     black body spectrum.
1320     .SH
1321     EXAMPLE
1322     .DS
1323     # Define an incandescent source material at 3000 degrees K
1324     m incand3000k =
1325     c
1326     cct 3000
1327     ed 1500
1328     .DE
1329     .SH
1330     SEE ALSO
1331     .LP
1332     .UL c,
1333     .UL cmix,
1334     .UL cspec,
1335     .UL cxy
1336     .ds RH CMIX
1337     .bp
1338     .SH
1339     NAME
1340     .LP
1341     cmix - mix two or more named colors to make the current color
1342     .SH
1343     SYNOPSIS
1344     .LP
1345     .B cmix
1346     .I "w1 c1 w2 c2 ..."
1347     .SH
1348     DESCRIPTION
1349     .LP
1350     The
1351     .UL cmix
1352     entity sums together two or more named colors using specified
1353     weighting coefficients, which correspond to the relative
1354     photometric brightness of each.
1355     As in all color specifications, the result is normalized so the
1356     absolute scale of the weights does not matter, only their relative
1357     values.
1358     .LP
1359     If any of the colors is a spectral quantity (i.e. from a
1360     .UL cspec
1361     or
1362     .UL cct
1363     entity), then all the colors are first converted to spectral
1364     quantities.
1365     This is done with an approximation for CIE (x,y) chromaticities,
1366     which may be problematic depending on their values.
1367     In general, it is safest to add together colors that are either
1368     all spectral quantities or all CIE quantities.
1369     .SH
1370     EXAMPLE
1371     .DS
1372     # Define RGB primaries for a standard color monitor
1373     c R =
1374     cxy 0.640 0.330
1375     c G =
1376     cxy 0.290 0.600
1377     c B =
1378     cxy 0.150 0.060
1379     # Mix them together in appropriate amounts for white
1380     c white =
1381     cmix 0.265 R 0.670 G 0.065 B
1382     .DE
1383     .SH
1384     SEE ALSO
1385     .LP
1386     .UL c,
1387     .UL cct,
1388     .UL cspec,
1389     .UL cxy
1390     .ds LH Material Entities
1391     .ds RH M
1392     .bp
1393     .SH
1394     NAME
1395     .LP
1396     m - get or set the current material context
1397     .SH
1398     SYNOPSIS
1399     .LP
1400     .B m
1401     [
1402     .I id
1403     [
1404     .B =
1405     [
1406     .I template
1407     ]
1408     ]
1409     ]
1410     .SH
1411     DESCRIPTION
1412     .LP
1413     If the
1414     .UL m
1415     keyword is given by itself, then it establishes
1416     the unnamed material context, which is a perfect two-sided black absorber.
1417     This context may be modified, but the changes will not be saved.
1418     .LP
1419     If the keyword is followed by an identifier
1420     .I id,
1421     then it reestablishes a previous context.
1422     If the specified context was never defined, an error will result.
1423     .LP
1424     If the entity is given with an identifier
1425     followed by an equals sign ('='), then a new context is established,
1426     and cleared to the default material.
1427     (Note that the equals sign must be separated from other
1428     arguments by white space to be properly recognized.)\0
1429     If the equals sign is followed by a second identifier
1430     .I template,
1431     then this previously defined material will be used as a source of
1432     default values instead.
1433     This may be used to establish a material alias, or to modify an
1434     existing material and give it a new name.
1435     .LP
1436     The sum of the diffuse and specular reflectances and transmittances
1437     must not be greater than one (with no negative values, obviously).
1438     These values are assumed to be measured at normal incidence.
1439     If an index of refraction is given, this may modify the balance between
1440     diffuse and specular reflectance at other incident angles.
1441     If the
1442     material is one-sided (see
1443     .UL sides
1444     entity), then it may be a dielectric interface.
1445     In this case, the specular transmittance given is that which would be
1446     measured at normal incidence for a pane of the material 5 mm thick.
1447     This is important for figuring the actual transmittance for non-planar
1448     geometries assuming a uniformly absorbing medium.
1449     (Diffuse transmittance will not be affected by thickness.)\0
1450     If the index of
1451     refraction has an imaginary part, then the surface is a metal and this
1452     implies other properties as well.
1453     The default index of refraction is that of a vacuum, i.e. (1,0).
1454     .SH
1455     EXAMPLE
1456     .DS
1457     # Define a blue enamel paint
1458     m blue_enamel =
1459     c
1460     cxy 0.2771 0.2975
1461     rd 0.5011
1462     c
1463     rs 0.0100 0.0350
1464     # Assign blue_enamel to be the color of the south wall
1465     m swall_mat = blue_enamel
1466     # ...
1467     # South wall face
1468     m swall_mat
1469     f sv1 sv2 sv3 sv4
1470     .DE
1471     .SH
1472     SEE ALSO
1473     .LP
1474     .UL ed,
1475     .UL ir,
1476     .UL rd,
1477     .UL rs,
1478     .UL sides,
1479     .UL td,
1480     .UL ts
1481     .ds RH SIDES
1482     .bp
1483     .SH
1484     NAME
1485     .LP
1486     sides - set the number of sides for the current material
1487     .SH
1488     SYNOPSIS
1489     .LP
1490     .B sides
1491     {
1492     .B 1
1493     |
1494     .B 2
1495     }
1496     .SH
1497     DESCRIPTION
1498     .LP
1499     The
1500     .UL sides
1501     entity is used to set the number of sides for the current material.
1502     If a surface is two-sided, then it will appear
1503     identical when viewed from either the front or the back.
1504     If a surface is one-sided,
1505     then it appears invisible when viewed from the back side.
1506     This means
1507     that a transmitting object will affect the light coming in through the
1508     front surface and ignore the characteristics of the back surface,
1509     unless the index of refraction is set.
1510     If the index of refraction is set, then the object will act as a
1511     solid piece of dielectric material.
1512     In either case, the transmission properties of the exiting surface
1513     should be the same as the incident surface for the model to be
1514     physically valid.
1515     .LP
1516     The default number of sides is two.
1517     .SH
1518     EXAMPLE
1519     .DS
1520     # Describe a blue crystal ball
1521     m blue_crystal =
1522     ir 1.650000 0
1523     # Solid dielectrics must use one-sided materials
1524     sides 1
1525     c
1526     rs 0.0602 0
1527     c
1528     cxy 0.3127 0.2881
1529     ts 0.6425 0
1530     v sc =
1531     p 10 15 1.5
1532     sph sc .02
1533     .DE
1534     .SH
1535     SEE ALSO
1536     .LP
1537     .UL ed,
1538     .UL ir,
1539     .UL m,
1540     .UL rd,
1541     .UL rs,
1542     .UL td,
1543     .UL ts
1544     .ds RH RD
1545     .bp
1546     .SH
1547     NAME
1548     .LP
1549     rd - set the diffuse reflectance for the current material
1550     .SH
1551     SYNOPSIS
1552     .LP
1553     .B rd
1554     .I rho_d
1555     .SH
1556     DESCRIPTION
1557     .LP
1558     Set the diffuse reflectance for the current material to
1559     .I rho_d
1560     using the current color to determine the spectral characteristics.
1561     This is the fraction of visible light that is reflected from a
1562     surface equally in all directions according to Lambert's law, and is
1563     often called the "Lambertian component."
1564     Photometric reflectance is measured according to v(lambda)
1565     response function of the 1931 CIE standard 2
1566     degree observer, and assumes an equal-energy white light source.
1567     The value must be between zero and one, and may be further
1568     restricted by the luminosity of the selected color.
1569     (I.e. it is impossible to have a violet material with a photometric
1570     reflectance close to one since the eye is less sensitive in this part
1571     of the spectrum.)\0
1572     .LP
1573     The default diffuse reflectance is zero.
1574     .SH
1575     EXAMPLE
1576     .DS
1577     # An off-white paint with 70% reflectance
1578     m flat_white70 =
1579     c
1580     cxy .3632 .3420
1581     rd .70
1582     .DE
1583     .SH
1584     SEE ALSO
1585     .LP
1586     .UL c,
1587     .UL ed,
1588     .UL ir,
1589     .UL m,
1590     .UL rs,
1591     .UL sides,
1592     .UL td,
1593     .UL ts
1594     .ds RH TD
1595     .bp
1596     .SH
1597     NAME
1598     .LP
1599     td - set the diffuse transmittance for the current material
1600     .SH
1601     SYNOPSIS
1602     .LP
1603     .B td
1604     .I tau_d
1605     .SH
1606     DESCRIPTION
1607     .LP
1608     Set the diffuse transmittance for the current material to
1609     .I tau_d
1610     using the current color to determine the spectral characteristics.
1611     This is the fraction of visible light that is transmitted through a
1612     surface equally in all (transmitted) directions.
1613     Like reflectance, transmittance is measured according to the
1614     standard v(lambda) curve, and assumes an equal-energy white light source.
1615     It is probably not possible to create a material with a diffuse
1616     transmittance above 50%, since well-diffused light will be reflected
1617     as well.
1618     .LP
1619     The default diffuse transmittance is zero.
1620     .SH
1621     EXAMPLE
1622     .DS
1623     # Model a perfect spherical diffuser, i.e. light hitting \
1624     either side will be scattered equally in all directions
1625     m wonderland_diffuser =
1626     c
1627     td .5
1628     rd .5
1629     .DE
1630     .SH
1631     SEE ALSO
1632     .LP
1633     .UL c,
1634     .UL ed,
1635     .UL ir,
1636     .UL m,
1637     .UL rd,
1638     .UL rs,
1639     .UL sides,
1640     .UL ts
1641     .ds RH ED
1642     .bp
1643     .SH
1644     NAME
1645     .LP
1646     ed - set the diffuse emittance for the current material
1647     .SH
1648     SYNOPSIS
1649     .LP
1650     .B ed
1651     .I epsilon_d
1652     .SH
1653     DESCRIPTION
1654     .LP
1655     Set the diffuse emittance for the current material to
1656     .I epsilon_d
1657     lumens per square meter using the current color to determine the
1658     spectral characteristics.
1659     Note that this is emittance rather than exitance, and therefore
1660     does not include reflected or transmitted light, which is a function
1661     of the other material settings and the illuminated environment.
1662     .LP
1663     The total lumen output of a convex emitting object
1664     is the radiating area of that object multiplied by its emittance.
1665     Therefore, one can compute the appropriate
1666     .I epsilon_d
1667     value for an emitter by dividing the total lumen output by the
1668     radiating area (in square meters).
1669     .LP
1670     The default emittance is zero.
1671     .SH
1672     EXAMPLE
1673     .DS
1674     # A 100-watt incandescent bulb (1600 lumens) modeled as a sphere
1675     m
1676     c
1677     cct 3000
1678     ed 87712
1679     v cent =
1680     p 0 0 0
1681     sph cent .0381
1682     .DE
1683     .SH
1684     SEE ALSO
1685     .LP
1686     .UL c,
1687     .UL ir,
1688     .UL m,
1689     .UL rd,
1690     .UL rs,
1691     .UL sides,
1692     .UL td,
1693     .UL ts
1694     .ds RH RS
1695     .bp
1696     .SH
1697     NAME
1698     .LP
1699     rs - set the specular reflectance for the current material
1700     .SH
1701     SYNOPSIS
1702     .LP
1703     .B rs
1704     .I "rho_s alpha_r"
1705     .SH
1706     DESCRIPTION
1707     .LP
1708     Set the specular reflectance for the current material to
1709     .I rho_s
1710     using the current color to determine the spectral characteristics.
1711     The surface roughness parameter is set to
1712     .I alpha_r,
1713     which is the RMS height of surface variations over the
1714     autocorrelation distance (equivalent to RMS facet slope).
1715     A roughness value of zero means a perfectly smooth surface, and
1716     values greater than 0.2 are unusual.
1717     (See application notes section 6.1.2 for a comparison between the
1718     roughness parameter and Phong specular power.)\0
1719     .LP
1720     The default specular reflectance is zero.
1721     .SH
1722     EXAMPLE
1723     .DS
1724     # Define a slightly rough brass metallic surface
1725     m rough_brass =
1726     c
1727     cxy .3820 .4035
1728     # 30% specular, 9% diffuse
1729     rs .30 .08
1730     rd .09
1731     .DE
1732     .SH
1733     SEE ALSO
1734     .LP
1735     .UL c,
1736     .UL ed,
1737     .UL ir,
1738     .UL m,
1739     .UL rd,
1740     .UL sides,
1741     .UL td,
1742     .UL ts
1743     .ds RH TS
1744     .bp
1745     .SH
1746     NAME
1747     .LP
1748     ts - set the specular transmittance for the current material
1749     .SH
1750     SYNOPSIS
1751     .LP
1752     .B ts
1753     .I "tau_s alpha_t"
1754     .SH
1755     DESCRIPTION
1756     .LP
1757     Set the specular transmittance for the current material to
1758     .I tau_s
1759     using the current color to determine the spectral characteristics.
1760     The effective surface roughness is set to
1761     .I alpha_t.
1762     Rays will be transmitted with the same distribution as they would
1763     have been reflected with if this roughness value were given to the
1764     .UL rs
1765     entity.
1766     .LP
1767     The default specular transmittance is zero.
1768     .SH
1769     EXAMPLE
1770     .DS
1771     # Define a green glass material (58% transmittance)
1772     m glass =
1773     sides 2
1774     ir 1.52 0
1775     c
1776     rs 0.0725 0
1777     c
1778     cxy .23 .38
1779     ts 0.5815 0
1780     # Define an uncolored translucent plastic (40% transmittance)
1781     m translucent =
1782     sides 2
1783     ir 1.4 0
1784     c
1785     rs .045 0
1786     ts .40 .05
1787     .DE
1788     .SH
1789     SEE ALSO
1790     .LP
1791     .UL c,
1792     .UL ed,
1793     .UL ir,
1794     .UL m,
1795     .UL rd,
1796     .UL rs,
1797     .UL sides,
1798     .UL td
1799     .ds RH IR
1800     .bp
1801     .SH
1802     NAME
1803     .LP
1804     ir - set the complex index of refraction for the current material
1805     .SH
1806     SYNOPSIS
1807     .LP
1808     .B ir
1809     .I "n_real n_imag"
1810     .SH
1811     DESCRIPTION
1812     .LP
1813     Set the index of refraction for the current material to
1814     .I (n_real,n_imag).
1815     If the material is a dielectric (as opposed to metallic), then
1816     .I n_imag
1817     should be zero.
1818     For solid dielectric objects, the material should be made one-sided.
1819     If it is being used for thin objects, then a two-sided
1820     material is appropriate.
1821     (See the
1822     .UL sides
1823     entity.)\0
1824     .LP
1825     The default index of refraction is that of a vacuum, (1,0).
1826     .SH
1827     EXAMPLE
1828     .DS
1829     # Define polished aluminum material
1830     m polished_aluminum =
1831     # Complex index of refraction (from physics table)
1832     ir .770058 6.08351
1833     c
1834     rs .75 0
1835     .DE
1836     .SH
1837     SEE ALSO
1838     .LP
1839     .UL c,
1840     .UL ed,
1841     .UL m,
1842     .UL rd,
1843     .UL rs,
1844     .UL sides,
1845     .UL td,
1846     .UL ts
1847     .ds LH Vertex Entities
1848     .ds RH V
1849     .bp
1850     .SH
1851     NAME
1852     .LP
1853     v - get or set the current vertex context
1854     .SH
1855     SYNOPSIS
1856     .LP
1857     .B v
1858     [
1859     .I id
1860     [
1861     .B =
1862     [
1863     .I template
1864     ]
1865     ]
1866     ]
1867     .SH
1868     DESCRIPTION
1869     .LP
1870     If the
1871     .UL v
1872     keyword is given by itself, then it establishes
1873     the unnamed vertex context, which is the origin with no normal.
1874     This context may be modified, but the changes will not be saved.
1875     (The unnamed vertex is never used except as a source of default
1876     values since all geometric entities call their vertices by name.)\0
1877     .LP
1878     If the keyword is followed by an identifier
1879     .I id,
1880     then it reestablishes a previous context.
1881     If the specified context was never defined, an error will result.
1882     .LP
1883     If the entity is given with an identifier
1884     followed by an equals sign ('='), then a new context is established,
1885     and cleared to the default vertex (the origin).
1886     (Note that the equals sign must be separated from other
1887     arguments by white space to be properly recognized.)\0
1888     If the equals sign is followed by a second identifier
1889     .I template,
1890     then this previously defined vertex will be used as a source of
1891     default values instead.
1892     This may be used to establish a vertex alias, or to modify an
1893     existing vertex and give it a new name.
1894     .LP
1895     A non-zero vertex normal must be given for
1896     certain entities, specifically
1897     .UL ring
1898     and
1899     .UL torus
1900     require a normal direction.
1901     An
1902     .UL f
1903     entity will interpolate vertex normals if given, and
1904     use the polygon plane normal otherwise.
1905     See the
1906     .UL prism
1907     entry for an explanation of how it interprets and uses vertex
1908     normals.
1909     The other entities ignore vertex normals if present.
1910     .LP
1911     The actual position and normal direction for a vertex is determined
1912     at the time of use by a geometric entity.
1913     Specifically, the transformation in effect at the time the vertex is
1914     defined is irrelevant.
1915     The only transformation that matters is the one that is applied to
1916     the geometry itself.
1917     This prevents double-transformation of vertices and allows one set
1918     of vertices to be used for multiple purposes, e.g. the front and
1919     back sides of a drawer.
1920     .SH
1921     EXAMPLE
1922     .DS
1923     # Make a capped cylinder
1924     v end1 =
1925     p 0 0 0
1926     n 0 0 -1
1927     v end2 =
1928     p 0 0 1
1929     cyl end1 1.2 end2
1930     # Forgot normal for end2
1931     v end2
1932     n 0 0 1
1933     ring end1 0 1.2
1934     ring end2 0 1.2
1935     .DE
1936     .SH
1937     SEE ALSO
1938     .LP
1939     .UL cone,
1940     .UL cyl,
1941     .UL f,
1942     .UL n,
1943     .UL p,
1944     .UL prism,
1945     .UL ring,
1946     .UL sph,
1947     .UL torus
1948     .ds RH P
1949     .bp
1950     .SH
1951     NAME
1952     .LP
1953     p - set the point location for the current vertex
1954     .SH
1955     SYNOPSIS
1956     .LP
1957     .B p
1958     .I "px py pz"
1959     .SH
1960     DESCRIPTION
1961     .LP
1962     Set the 3-dimensional position for the current vertex to
1963     .I (px,py,pz).
1964     The actual position of the vertex will be determined by the
1965     transformation in effect at the time the vertex is applied to a
1966     geometric surface entity.
1967     The transform current when the position is set is irrelevant.
1968     .LP
1969     The default vertex position is the origin, (0,0,0).
1970     .SH
1971     EXAMPLE
1972     .DS
1973     # Make a small circle of 6 spheres
1974     v scent =
1975     p 1 0 0
1976     xf -a 6 -rz 60
1977     sph scent .05
1978     xf
1979     .DE
1980     .SH
1981     SEE ALSO
1982     .LP
1983     .UL cone,
1984     .UL cyl,
1985     .UL f,
1986     .UL n,
1987     .UL prism,
1988     .UL ring,
1989     .UL sph,
1990     .UL torus,
1991     .UL v
1992     .ds RH N
1993     .bp
1994     .SH
1995     NAME
1996     .LP
1997     n - set the surface normal direction for the current vertex
1998     .SH
1999     SYNOPSIS
2000     .LP
2001     .B n
2002     .I "dx dy dz"
2003     .SH
2004     DESCRIPTION
2005     .LP
2006     Set the 3-dimensional surface normal for the current vertex to the
2007     normalized vector along
2008     .I (dx,dy,dz).
2009     If this vector is zero, then the surface normal is effectively
2010     unset.
2011     The actual surface normal orientation of the vertex will be determined
2012     by the transformation in effect at the time the vertex is applied to a
2013     geometric surface entity.
2014     The current transform when the normal is set is irrelevant.
2015     .LP
2016     The default vertex normal is the zero vector (i.e. no normal).
2017     .SH
2018     EXAMPLE
2019     .DS
2020     # Make a chain of 10 interlocking doughnuts
2021     v tcent =
2022     p 0 0 0
2023     n 0 1 0
2024     xf -a 10 -rx 90 -t .2 0 0
2025     torus tcent .1 .2
2026     xf
2027     .DE
2028     .SH
2029     SEE ALSO
2030     .LP
2031     .UL f,
2032     .UL p,
2033     .UL prism,
2034     .UL ring,
2035     .UL torus,
2036     .UL v
2037     .ds LH Geometric Entities
2038     .ds RH F
2039     .bp
2040     .SH
2041     NAME
2042     .LP
2043     f - create an N-sided polygonal face
2044     .SH
2045     SYNOPSIS
2046     .LP
2047     .B f
2048     .I "v1 v2 ... vN"
2049     .SH
2050     DESCRIPTION
2051     .LP
2052     Create a polygonal face made of the current material
2053     by connecting the named vertices in order, and connecting the last
2054     vertex to the first.
2055     There must be at least three vertices, and if any vertex is undefined,
2056     an error will result.
2057     .LP
2058     The surface orientation is determined by the right-hand rule; when
2059     the curl of the fingers follows the given order of the vertices, the
2060     surface normal points in the thumb direction.
2061     Face vertices should be coplanar, though this is difficult to guarantee
2062     in a 3-dimensional specification.
2063     .LP
2064     If any vertices have associated surface normals, they will be used
2065     instead of the average plane normal, though it is safest to specify
2066     either all normals or no normals, and to stick with triangles
2067     when normals are used.
2068     Also, specified normals should point in the general direction of the
2069     surface for best results.
2070     .LP
2071     There is no explicit representation of holes in MGF. A hole must be
2072     represented implicitly by connecting vertices to form "seams." For
2073     example, a wall with a window in it might look as shown in Figure 1.
2074     In many systems, the wall itself would be represented with the first
2075     list of vertices, (v1,v2,v3,v4) and the hole associated with that
2076     wall as a second set of vertices (v5,v6,v7,v8). In MGF, we must
2077     give the whole thing as a single polygon, connecting the vertices so
2078     as to create a "seam," as shown in Figure 2.
2079     This could be written in MGF as "f v1 v2 v3 v4 v5 v6 v7 v8 v5 v4".
2080     .LP
2081     It is very important that the order of the hole be opposite to the
2082     order of the outer perimeter, otherwise the polygon will be
2083     "twisted" on top of itself. Note also that the seam was traversed
2084     in both directions, once going from v4 to v5, and again returning
2085     from v5 to v4. This is a necessary condition for a proper seam.
2086     .LP
2087     The choice of vertices to make into a seam is somewhat arbitrary, but
2088     some rendering systems may not give sane results if you cross over a
2089     hole with part of your seam. If we had chosen to create the seam
2090     between v2 and v5 in the above example instead of v4 and v5, the seam
2091     would cross our hole and may not render correctly\(dg.
2092     .FS
2093     \(dgFor systems that
2094     are sensitive to this, it is probably safest for their MGF
2095     loader/translator to re-expresses seams in terms of holes again, which can
2096     be done easily so long as vertices are shared in the fashion shown.
2097     .FE
2098     .bp
2099     Replace this page with the first page from "figures.ps".
2100     .bp
2101     .SH
2102     EXAMPLE
2103     .DS
2104     # Make a pyramid
2105     v apex =
2106     p 1 1 1
2107     v base0 =
2108     p 0 0 0
2109     v base1 =
2110     p 0 2 0
2111     v base2 =
2112     p 2 2 0
2113     v base3 =
2114     p 2 0 0
2115     # Bottom
2116     f base0 base1 base2 base3
2117     # Sides
2118     f base0 apex base1
2119     f base1 apex base2
2120     f base2 apex base3
2121     f base3 apex base0
2122     .DE
2123     .SH
2124     SEE ALSO
2125     .LP
2126     .UL cone,
2127     .UL cyl,
2128     .UL m,
2129     .UL prism,
2130     .UL ring,
2131     .UL sph,
2132     .UL torus,
2133     .UL v
2134     .ds RH SPH
2135     .bp
2136     .SH
2137     NAME
2138     .LP
2139     sph - create a sphere
2140     .SH
2141     SYNOPSIS
2142     .LP
2143     .B sph
2144     .I "vc rad"
2145     .SH
2146     DESCRIPTION
2147     .LP
2148     Create a sphere made of the current material with its center at the
2149     named vertex
2150     .I vc
2151     and a radius of
2152     .I rad.
2153     If the vertex is undefined an error will result.
2154     .LP
2155     The surface normal is usually directed outward, but will be directed
2156     inward if the given radius is negative.
2157     (This typically matters only for one-sided materials.)\0
2158     A zero radius is illegal.
2159     .SH
2160     EXAMPLE
2161     .DS
2162     # Create a thick glass sphere with a hollow inside
2163     m glass =
2164     sides 1
2165     ir 1.52 0
2166     c
2167     rs .06 0
2168     ts .88 0
2169     v cent =
2170     p 0 0 1.1
2171     # The outer shell
2172     sph cent .1
2173     # The inner bubble
2174     sph cent -.08
2175     .DE
2176     .SH
2177     SEE ALSO
2178     .LP
2179     .UL cone,
2180     .UL cyl,
2181     .UL f,
2182     .UL m,
2183     .UL prism,
2184     .UL ring,
2185     .UL torus,
2186     .UL v
2187     .ds RH CYL
2188     .bp
2189     .SH
2190     NAME
2191     .LP
2192     cyl - create an open-ended, truncated right cylinder
2193     .SH
2194     SYNOPSIS
2195     .LP
2196     .B cyl
2197     .I "v1 rad v2"
2198     .SH
2199     DESCRIPTION
2200     .LP
2201     Create a truncated right cylinder of radius
2202     .I rad
2203     using the current material, starting at the named vertex
2204     .I v1
2205     and continuing to
2206     .I v2.
2207     The ends will be open, but may be capped using the
2208     .UL ring
2209     entity if desired.
2210     .LP
2211     The surface normal will usually be directed outward, but may be
2212     directed inward by giving a negative value for
2213     .I rad.
2214     A zero radius is illegal, and
2215     .I v1
2216     cannot equal
2217     .I v2.
2218     .SH
2219     EXAMPLE
2220     .DS
2221     # A stylus with one rounded and one pointed end
2222     o stylus
2223     v vtip0 =
2224     p 0 0 0
2225     v vtip1 =
2226     p 0 0 .005
2227     v vend =
2228     p 0 0 .05
2229 greg 1.5 cyl vtip1 .0015 vend
2230 greg 1.1 sph vend .0015
2231     cone vtip0 0 vtip1 .0015
2232     o
2233     .DE
2234     .SH
2235     SEE ALSO
2236     .LP
2237     .UL cone,
2238     .UL f,
2239     .UL m,
2240     .UL prism,
2241     .UL ring,
2242     .UL sph,
2243     .UL torus,
2244     .UL v
2245     .ds RH CONE
2246     .bp
2247     .SH
2248     NAME
2249     .LP
2250     cone - create an open-ended, truncated right cone
2251     .SH
2252     SYNOPSIS
2253     .LP
2254     .B cone
2255     .I "v1 rad1 v2 rad2"
2256     .SH
2257     DESCRIPTION
2258     .LP
2259     Create a truncated right cone using the current material.
2260     The starting radius is
2261     .I rad1
2262     at
2263     .I v1
2264     and the ending radius is
2265     is
2266     .I rad2
2267     at
2268     .I v2.
2269     The ends will be open, but may be capped using the
2270     .UL ring
2271     entity if desired.
2272     .LP
2273     The surface normal will usually be directed outward, but may be
2274     directed inward by giving negative values for both radii.
2275     (It is illegal for the signs of the two radii to disagree.)\0
2276     One but not both radii may be zero, indicating that the cone comes
2277     to a point.
2278     .LP
2279     Although it is not strictly forbidden to have equal cone radii, the
2280     .UL cyl
2281     entity should be used in such cases.
2282     Likewise, the
2283     .UL ring
2284     entity must be used if
2285     .I v1
2286     and
2287     .I v2
2288     are equal.
2289     .SH
2290     EXAMPLE
2291     .DS
2292     # A parasol
2293     o parasol
2294     v v1 =
2295     p 0 0 0
2296     v v2 =
2297     p 0 0 .75
2298     v v3 =
2299     p 0 0 .7
2300     m handle_mat
2301     cyl v1 .002 v2
2302     m parasol_paper
2303     cyl v2 0 v3 .33
2304     o
2305     .DE
2306     .SH
2307     SEE ALSO
2308     .LP
2309     .UL cyl,
2310     .UL f,
2311     .UL m,
2312     .UL prism,
2313     .UL ring,
2314     .UL sph,
2315     .UL torus,
2316     .UL v
2317     .ds RH PRISM
2318     .bp
2319     .SH
2320     NAME
2321     .LP
2322     prism - create a closed right prism
2323     .SH
2324     SYNOPSIS
2325     .LP
2326     .B prism
2327     .I "v1 v2 ... vN length"
2328     .SH
2329     DESCRIPTION
2330     .LP
2331     Create a closed right prism using the current material.
2332     One end face will be enclosed by the named vertices, and the
2333     opposite end face will be a mirror image at a distance
2334     .I length
2335     from the original.
2336     The edges will be extruded into N quadrilaterals connecting
2337     the two end faces.
2338     .LP
2339     The order of vertices determines the original face orientation
2340     according to the right-hand rule as explained for the
2341     .UL f
2342     entity.
2343     Normally, the prism is extruded in the direction opposite to the
2344     original surface normal, resulting in faces that all point outward.
2345     If the specified
2346     .I length
2347     is negative, the prism will be extruded above the original face
2348     and all surface normals will point inward.
2349     .LP
2350     If the vertices have associated normals, they are applied to the
2351     side faces only, and should generally point in the appropriate
2352     direction (i.e. in or out depending on whether
2353     .I length
2354     is negative or positive).
2355     .SH
2356     EXAMPLE
2357     .DS
2358     # Make a unit cube starting at the origin and \\\\
2359     extending to the positive octant
2360     v cv0 =
2361     p 0 0 0
2362     v cv1 =
2363     p 0 1 0
2364     v cv2 =
2365     p 1 1 0
2366     v cv3 =
2367     p 1 0 0
2368     # Right hand rule has original face looking in -Z direction
2369     prism cv0 cv1 cv2 cv3 1
2370     .DE
2371     .SH
2372     SEE ALSO
2373     .LP
2374     .UL cyl,
2375     .UL cone,
2376     .UL f,
2377     .UL m,
2378     .UL ring,
2379     .UL sph,
2380     .UL torus,
2381     .UL v
2382     .ds RH RING
2383     .bp
2384     .SH
2385     NAME
2386     .LP
2387     ring - create a circular ring with inner and outer radii
2388     .SH
2389     SYNOPSIS
2390     .LP
2391 greg 1.7 .B ring
2392 greg 1.1 .I "vc rmin rmax"
2393     .SH
2394     DESCRIPTION
2395     .LP
2396     Create a circular face of the current material centered on the named
2397     vertex
2398     .I vc
2399     with an inner radius of
2400     .I rmin
2401     and an outer radius of
2402     .I rmax.
2403     The surface orientation is determined by the normal vector
2404     associated with
2405     .I vc.
2406     If this vertex is undefined or has no normal, an error will result.
2407     The minimum radius may be equal to but not less than zero, and the
2408     maximum radius must be strictly greater than the minimum.
2409     .SH
2410     EXAMPLE
2411     .DS
2412     # The proverbial brass ring
2413     o brass_ring
2414     m brass
2415     v end1 =
2416     p 0 -.005 0
2417     n 0 -1 0
2418     v end2 =
2419     p 0 .005 0
2420     n 0 1 0
2421     ring end1 .02 .03
2422     cyl end1 .03 end2
2423     ring end2 .02 .03
2424     cyl end2 -.02 end1
2425     o
2426     .DE
2427     .SH
2428     SEE ALSO
2429     .LP
2430     .UL cyl,
2431     .UL cone,
2432     .UL f,
2433     .UL m,
2434     .UL prism,
2435     .UL sph,
2436     .UL torus,
2437     .UL v
2438     .ds RH TORUS
2439     .bp
2440     .SH
2441     NAME
2442     .LP
2443     torus - create a regular torus
2444     .SH
2445     SYNOPSIS
2446     .LP
2447     .B torus
2448     .I "vc rmin rmax"
2449     .SH
2450     DESCRIPTION
2451     .LP
2452     Create a torus of the current material centered on the named vertex
2453     .I vc
2454     with an inner radius of
2455     .I rmin
2456     and an outer radius of
2457     .I rmax.
2458     The plane of the torus will be perpendicular to the normal vector
2459     associated with
2460     .I vc.
2461     If this vertex is undefined or has no normal, an error will result.
2462     .LP
2463     If a torus with an inward facing surface normal is desired,
2464     .I rmin
2465     and
2466     .I rmax
2467     may be negative.
2468     The minimum radius may be zero, but may not be negative when
2469     .I rmax
2470     is positive or vice versa.
2471     The magnitude or
2472     .I rmax
2473     must always be strictly greater than that of
2474     .I rmin.
2475     .SH
2476     EXAMPLE
2477     .DS
2478     # The proverbial brass ring -- easy grip version
2479     o brass_ring
2480     m brass
2481     v center =
2482     p 0 0 0
2483     n 0 1 0
2484     torus center .02 .03
2485     o
2486     .DE
2487     .SH
2488     SEE ALSO
2489     .LP
2490     .UL cyl,
2491     .UL cone,
2492     .UL f,
2493     .UL m,
2494     .UL prism,
2495     .UL ring,
2496     .UL sph,
2497     .UL v
2498     .ds RH
2499     .ds LH
2500     .bp
2501     .NH
2502     MGF Translators
2503     .LP
2504     Initially, there are four translators for MGF data, but only
2505     one of these is distributed with the MGF parser itself,
2506     .I mgfilt.
2507     Two of the other translators,
2508     .I mgf2rad
2509     and
2510     .I rad2mgf
2511     convert between MGF and the Radiance scene description language,
2512     and are distributed for free with the rest of the Radiance
2513     package\(dg.
2514     .FS
2515     \(dgRadiance is available by anonymous ftp from hobbes.lbl.gov and
2516     nestor.epfl.ch, or by WWW from
2517     "http://radsite.lbl.gov/radiance/HOME.html"
2518     .FE
2519     A third translator,
2520     .I mgf2meta,
2521     converts to a 2-dimensional line plot, and is also
2522     distributed with Radiance.
2523     .LP
2524     Mgfilt is a simple but useful utility that takes MGF on its input
2525     and produces MGF on its output.
2526     It uses the parser to convert entities that are not wanted or
2527     understood, and produces only the requested ones.
2528     This is useful for seeing what exactly a program must understand
2529     when it supports a given set of entities, and may serve as a
2530     substitute for linking to the parser library for programmers who
2531     wish to interpret the ASCII input directly but without all the
2532     unwanted entities.
2533     In future releases of MGF, this utility will also be handy for
2534     taking new entities and producing older versions of MGF for
2535     translators that have not yet been updated properly.
2536     .ds LH Translators
2537     .ds RH MGFILT
2538     .bp
2539     .SH
2540     NAME
2541     .LP
2542     mgfilt - get usable MGF entities from input
2543     .SH
2544     SYNOPSIS
2545     .LP
2546     .B mgfilt
2547     .B version
2548     [
2549     .B input ..
2550     ]
2551     .br
2552     or
2553     .br
2554     .B mgfilt
2555     .B "e1,e2,.."
2556     [
2557     .B input ..
2558     ]
2559     .SH
2560     DESCRIPTION
2561     .LP
2562     .I Mgfilt
2563     takes one or more MGF input files and converts all the entities to
2564     the types listed.
2565     In the first form, a single integer is given for the
2566     .I version
2567     of MGF that is to be produced.
2568     Since MGF is in its first major release, this is not yet a useful
2569     form, but it will be when the second major release comes out.
2570 greg 1.9 This has the necessary side-effect of expanding all included files.
2571     (See the
2572     .UL i
2573     entity.)\0
2574 greg 1.1 .LP
2575     In the second form,
2576     .I mgfilt
2577     produces only the entities listed in the first argument, which must
2578     be comma-separated.
2579     The listed entity order is not important, but all entities given
2580     must be defined in the current version of MGF.
2581     Unknown entities will be summarily discarded on the input, and a
2582     warning message will be printed to the standard error.
2583     .SH
2584     EXAMPLES
2585     .LP
2586     To take an MGF version 3 file and send it to a version 2
2587     translator:
2588     .IP
2589     mgfilt 2 input.mgf | mgf2rad > input.rad
2590     .LP
2591     To take an MGF file and produce only flat polygonal faces
2592     with no materials:
2593     .IP
2594     mgfilt f,v,p,xf input.mgf > flatpoly.mgf
2595     .SH
2596     SEE ALSO
2597     .LP
2598 greg 1.9 i, mgf2rad, rad2mgf
2599 greg 1.1 .ds RH MGF2RAD
2600     .bp
2601     .SH
2602     NAME
2603     .LP
2604     mgf2rad - convert Materials and Geometry Format file to RADIANCE description
2605     .SH
2606     SYNOPSIS
2607     .LP
2608     .B mgf2rad
2609     [
2610     .B "\-m matfile"
2611     ][
2612     .B "\-e mult"
2613     ][
2614     .B "\-g dist"
2615     ]
2616     [
2617     .B input ..
2618     ]
2619     .SH
2620     DESCRIPTION
2621     .LP
2622     .I Mgf2rad
2623     converts one or more Materials and Geometry Format (MGF)
2624     files to a RADIANCE scene description.
2625     By definition, all output dimensions are in meters.
2626     The material names and properties
2627     for the surfaces will be those assigned in MGF.
2628     Any materials not defined in MGF will result in an error during
2629     translation.
2630     Light sources are described inline as IES luminaire files, and
2631     .I mgf2rad
2632     calls the program
2633     .I ies2rad(1)
2634     to translate these files.
2635     If an IES file in turn contains an MGF description of the local
2636     fixture geometry, this may result in a recursive call to
2637     .I mgf2rad,
2638     which is normal and should be transparent.
2639     The only side-effect of this additional translation is the
2640     appearance of other RADIANCE scene and data files produced
2641     automatically by
2642     .I ies2rad.
2643     .LP
2644     The
2645     .I \-m
2646     option may be used to put all the translated materials into a separate
2647     RADIANCE file.
2648     This is not always advisable, as any given material name may be
2649     reused at different points in the MGF description, and writing them
2650     to a separate file loses the contextual association between
2651     materials and surfaces.
2652     As long as unique material names are used throughout the MGF
2653     description and material properties are not redefined, there
2654     will be no problem.
2655     Note that this is the only way to get all the translated materials
2656     into a single file, since no output is produced for unreferenced
2657     materials; i.e. translating just the MGF materials does not work.
2658     .LP
2659     The
2660     .I \-e
2661     option may be used to multiply all the emission values by the
2662     given
2663     .I mult
2664     factor.
2665     The
2666     .I \-g
2667     option may be used to establish a glow distance (in meters)
2668     for all emitting surfaces.
2669     These two options are employed principally by
2670     .I ies2rad,
2671     and are not generally useful to most users.
2672     .SH
2673     EXAMPLES
2674     .LP
2675     To translate two MGF files into one RADIANCE materials file and
2676     one geometry file:
2677     .IP
2678     mgf2rad -m materials.rad building1.mgf building2.mgf > building1+2.rad
2679     .LP
2680     To create an octree directly from two MGF files and one RADIANCE
2681     file:
2682     .IP
2683     oconv '\\!mgf2rad materials.mgf scene.mgf' source.rad > scene.oct
2684     .SH
2685     FILES
2686     .LP
2687     tmesh.cal Used to smooth polygonal geometry
2688     .br
2689     *.rad RADIANCE source descriptions created by ies2rad
2690     .br
2691     *.dat RADIANCE source data created by ies2rad
2692     .br
2693     source.cal Used for IES source coordinates
2694     .SH
2695     AUTHOR
2696     .LP
2697     Greg Ward
2698     .SH
2699     SEE ALSO
2700     .LP
2701     ies2rad(1), mgf2meta(1), obj2rad(1), oconv(1), rad2mgf(1), xform(1)
2702 greg 1.3 .ds RH RAD2MGF
2703 greg 1.1 .bp
2704     .SH
2705     NAME
2706     .LP
2707     rad2mgf - convert RADIANCE scene description to Materials and Geometry Format
2708     .SH
2709     SYNOPSIS
2710     .LP
2711     .B rad2mgf
2712     [
2713     .B \-dU
2714     ]
2715     [
2716     .B input ..
2717     ]
2718     .SH
2719     DESCRIPTION
2720     .LP
2721     .I Rad2mgf
2722     converts one or more RADIANCE scene files
2723     to the Materials and Geometry Format (MGF).
2724     Input units are specified with the
2725     .I \-mU
2726     option, where
2727     .I U
2728     is one of 'm' (meters), 'c' (centimeters), 'f' (feet) or 'i'
2729     (inches).
2730     The assumed unit is meters, which is the required output unit for
2731     MGF (thus the need to know).
2732     If the input dimensions are in none of these units, then the user
2733     should apply
2734     .I xform(1)
2735     with the
2736     .I \-s
2737     option to bring the units into line prior to translation.
2738     .LP
2739     The MGF material names and properties
2740     for the surfaces will be those assigned in RADIANCE.
2741     If a referenced material has not been defined, then its name will
2742     be invoked in the MGF output without definition, and the description
2743     will be incomplete.
2744     .SH
2745     LIMITATIONS
2746     .LP
2747     Although MGF supports all of the geometric types and the most
2748     common material types used in RADIANCE, there is currently no
2749     support for advanced BRDF materials, patterns, textures or mixtures.
2750     Also, the special types "source" and "antimatter" are not supported,
2751     and all light source materials are converted to simple diffuse emitters
2752     (except "illum" materials, which are converted to their alternates).
2753     These primitives are reproduced as comments in the output and
2754     must be replaced manually if necessary.
2755     .LP
2756     The RADIANCE "instance" type is treated specially.
2757     .I Rad2mgf
2758     converts each instance to an MGF include statement, using the corresponding
2759     transformation and a file name derived from the octree name.
2760     (The original octree suffix is replaced by ".mgf".)\0
2761     For this to work, the user must separately create the referenced
2762     MGF files from the original RADIANCE descriptions.
2763     The description file names can usually be determined using the
2764     .I getinfo(1)
2765     command run on the octrees in question.
2766     .SH
2767     EXAMPLES
2768     .LP
2769     To convert three RADIANCE files (in feet) to one MGF file:
2770     .IP
2771     mgf2rad -df file1.rad file2.rad file3.rad > scene.mgf
2772     .LP
2773     To translate a RADIANCE materials file to MGF:
2774     .IP
2775     mgf2rad materials.rad > materials.mgf
2776     .SH
2777     AUTHOR
2778     .LP
2779     Greg Ward
2780     .SH
2781     SEE ALSO
2782     .LP
2783     getinfo(1), ies2rad(1), mgf2meta(1), mgf2rad(1), obj2rad(1), oconv(1), xform(1)
2784     .ds RH MGF2META
2785     .bp
2786     .SH
2787     NAME
2788     .LP
2789     mgf2meta - convert Materials and Geometry Format file to Metafile graphics
2790     .SH
2791     SYNOPSIS
2792     .LP
2793     .B mgf2meta
2794     [
2795     .B "-t threshold"
2796     ]
2797     .B "{x|y|z} xmin xmax ymin ymax zmin zmax"
2798     [
2799     .B input ..
2800     ]
2801     .SH
2802     DESCRIPTION
2803     .LP
2804     .I Mgf2meta
2805     converts one or more Materials and Geometry Format (MGF)
2806     files to a 2-D orthographic projection along the selected axis in the
2807     .I metafile(1)
2808     graphics format.
2809     All geometry is clipped to the specified bounding box, and the
2810     resulting orientation is as follows:
2811     .sp .5
2812     .nf
2813     Projection Orientation
2814     ======= ========
2815     x Y-axis right, Z-axis up
2816     y Z-axis right, X-axis up
2817     z X-axis right, Z-axis up
2818     .fi
2819     .LP
2820     If multiple input files are given, the first file prints in black,
2821     the second prints in red, the third in green and the fourth in blue.
2822     If more than four input files are given, they cycle through the
2823     colors again in three other line types: dashed, dotted and
2824     dot-dashed.
2825     .LP
2826     The
2827     .I \-t
2828     option may be used to randomly throw out line segments that are
2829     shorter than the given
2830     .I threshold
2831     (given as a fraction of the plot width).
2832     Segments are included with a
2833     probability equal to the square of the line length over the square
2834     of the threshold.
2835     This can greatly reduce the number of lines in the drawing (and
2836     therefore improve the drawing speed) with only a modest loss in
2837     quality.
2838     A typical value for this parameter is 0.005.
2839     .LP
2840     All MGF material information is ignored on the input.
2841     .SH
2842     EXAMPLES
2843     .LP
2844     To project two MGF files along the Z-axis and display them under
2845     X11:
2846     .IP
2847     mgf2meta z 0 10 0 15 0 9 building1.mgf building2.mgf | x11meta
2848     .LP
2849     To convert a RADIANCE scene to a line drawing in RADIANCE picture
2850     format:
2851     .IP
2852     rad2mgf scene.rad | mgf2meta x `getbbox -h scene.rad` | meta2tga |
2853     ra_t8 -r > scene.pic
2854     .SH
2855     AUTHOR
2856     .LP
2857     Greg Ward
2858     .SH
2859     SEE ALSO
2860     .LP
2861     getbbox(1), meta2tga(1), metafile(5), mgf2rad(1), pflip(1),
2862     protate(1), psmeta(1), ra_t8(1), rad2mgf(1), t4014(1), x11meta(1)
2863     .ds RH
2864     .ds LH
2865     .bp
2866     .NH
2867     MGF Parser Library
2868     .LP
2869     The principal motivation for creating a standard parser library for
2870     MGF is to make it easy for software developers to offer some base
2871     level of compliance.
2872     The key to making MGF easy to support in fact is the parser, which
2873     has the ability to express higher order entities in terms of
2874     lower order ones.
2875     For example, tori are part of the MGF specification, but if a given
2876     program or translator does not support them, the parser will convert
2877     them to cones.
2878     If cones are not supported either, it will convert them further into
2879     smoothed polygons.
2880     If smoothing (vertex normal information) is not supported, it will
2881     be ignored and the program will just get flat polygons.
2882     This is done in such a way that future versions of the standard may
2883     include new entities that old software does not even have to know
2884     about, and they will be converted appropriately.
2885     Forward compatibility is thus built right into the parser loading
2886     mechanism itself -- the programmer simply links to the new code and
2887     the new standard is supported without any further changes.
2888     .SH
2889     Language
2890     .LP
2891     The provided MGF parser is written in ANSI-C.
2892     This language was chosen for reasons of portability and efficiency.
2893     Almost all systems support some form of ANSI-compatible C, and many
2894     languages can cross-link to C libraries without modification.
2895     Backward compatibility to Kernighan and Ritchie C is achieved by
2896     compiling with the -DNOPROTO flag.
2897     .LP
2898     All of the data structures and prototypes needed for the library
2899     are in the header file "parser.h".
2900     This file is the best resource for the parser and is updated with
2901     each MGF release.
2902     .SH
2903     Mechanism
2904     .LP
2905     The parser works by a simple callback mechanism to routines that
2906     actually interpret the individual entities.
2907     Some of these routines will belong to the calling program, and some
2908     will be entity support routines included in the library itself.
2909     There is a global array of function pointers, called
2910     .I mg_ehand.
2911     It is defined thus:
2912     .DS
2913     extern int (*mg_ehand[MG_NENTITIES])(int argc, char **argv);
2914     .DE
2915     Before parsing begins, this dispatch table is initialized to point to the
2916     routines that will handle each supported entity.
2917     Every entity handler has the same basic prototype, which is the
2918     same as the
2919     .I main
2920     function, i.e:
2921     .DS
2922     extern int \f2handler\f1(int argc, char **argv);
2923     .DE
2924     The first argument is the number of words in the MGF entity
2925     (counting the entity itself) and the second argument is an array of
2926     nul-terminated strings with the entity and its arguments.
2927     The function should return zero or one of the error
2928     codes defined in "parser.h".
2929     A non-zero return value causes the parser to abort, returning the
2930     error up through its call stack to the entry function, usually
2931     .I mg_load.
2932     .LP
2933     A special function pointer for undefined entities is
2934     defined as follows:
2935     .DS
2936     extern int (*mg_uhand)(int argc, char **argv);
2937     .DE
2938     By default, this points to the library function
2939     .I mg_defuhand,
2940     which prints an error message on the first unknown entity and keeps a
2941     count from then on, which is stored in the global unsigned integer
2942     .I mg_nunknown.
2943     If the
2944     .I mg_uhand
2945     pointer is assigned a value of NULL instead, parsing will abort at the
2946     first unrecognized entity.
2947     The reason this is not the default action is that ignoring unknown entities
2948     offers a certain base level of forward compatibility.
2949     Ignoring things one does not understand is not the best approach, but it
2950     is usually better than quitting with an error message if the input is
2951     in fact valid, but is a later version of the standard.
2952     The real solution is to update the interpreter by linking to a new version
2953     of the parser, or use a new version of the
2954     .I mgfilt
2955     command to convert the new MGF input to an older standard.
2956     .LP
2957     The
2958     .I mg_uhand
2959     pointer may also be used to customize the language for a particular
2960     application by adding entities, though this is discouraged because it
2961     tends to weaken the standard.
2962     .LP
2963     The skeletal framework for an MGF loader or translator is to assign
2964     function pointers to the
2965     .I mg_ehand
2966     array, call the parser initialization function
2967     .I mg_init,
2968     then call the file loader function
2969     .I mg_load
2970     once for each input file.
2971     This will in turn make calls back to the functions assigned to
2972     .I mg_ehand.
2973     To give a simple example, let us look at a
2974     translator that understands only flat polygonal faces, putting out
2975     vertex locations immediately after each "face" keyword:
2976     .DS
2977     #include <stdio.h>
2978     #include "parser.h"
2979    
2980     int
2981     myfaceh(ac, av) /* face handling routine */
2982     int ac;
2983     char **av;
2984     {
2985     C_VERTEX *vp; /* vertex structure pointer */
2986     FVECT vert; /* vertex point location */
2987     int i;
2988    
2989     if (ac < 4) /* check # arguments */
2990     return(MG_EARGC);
2991 greg 1.2 printf("face\\\\n"); /* begin face output */
2992 greg 1.1 for (i = 1; i < ac; i++) {
2993     if ((vp = c_getvert(av[i])) == NULL) /* vertex from name */
2994     return(MG_EUNDEF);
2995     xf_xfmpoint(vert, vp->p); /* apply transform */
2996 greg 1.2 printf("%15.9f %15.9f %15.9f\\\\n",
2997 greg 1.1 vert[0], vert[1], vert[2]); /* output vertex */
2998     }
2999 greg 1.2 printf(";\\\\n"); /* end of face output */
3000 greg 1.1 return(MG_OK); /* normal exit */
3001     }
3002    
3003     main(argc, argv) /* translate MGF file(s) */
3004     int argc;
3005     char **argv;
3006     {
3007     int i;
3008     /* initialize dispatch table */
3009     mg_ehand[MG_E_FACE] = myfaceh; /* ours */
3010     mg_ehand[MG_E_VERTEX] = c_hvertex; /* parser lib */
3011     mg_ehand[MG_E_POINT] = c_hvertex; /* parser lib */
3012     mg_ehand[MG_E_XF] = xf_handler; /* parser lib */
3013     mg_init(); /* initialize parser */
3014     for (i = 1; i < argc; i++) /* load each file argument */
3015     if (mg_load(argv[i]) != MG_OK) /* and check for error */
3016     exit(1);
3017     exit(0); /* all done! */
3018     }
3019     .DE
3020     Hopefully, this example demonstrates just how easy it is to
3021     write an MGF translator.
3022     Of course, translators get more complicated the more entity
3023     types they support, but the point is that one does not
3024     .I have
3025     to support every entity -- the parser handles what the translator
3026     does not.
3027     Also, the library includes many general entity handlers,
3028     further reducing the burden on the programmer.
3029     This same principle means that it is not necessary to modify an
3030     existing program to accommodate a new version of MGF -- one need only
3031     link to the new parser library to comply with the new standard.
3032     .SH
3033     Division of Labor
3034     .LP
3035     As seen in the previous example, there are two parser routines that
3036     are normally called directly in an MGF translator or loader program.
3037     The first is
3038     .I mg_init,
3039     which takes no arguments but relies on the program having
3040     initialized those parts of the global
3041     .I mg_ehand
3042     array it cares about.
3043     The second routine is
3044     .I mg_load,
3045     which is called once on each input file.
3046     (A third routine,
3047     .I mg_clear,
3048     may be called to free the parser data structures after each file or
3049     after all files, if the program plans to continue rather than
3050     exit.)\0
3051     .LP
3052     The rest of the routines in a translator or loader program are
3053     called indirectly through the
3054     .I mg_ehand
3055     dispatch table, and they are the ones that do the real work of
3056     supporting the MGF entities.
3057     In addition to converting or discarding entities that the calling
3058     program does not know or care about, the parser library includes a
3059     set of context handlers that greatly simplify the translation
3060     process.
3061     There are three handlers for each of the three named contexts and
3062     their constituents, and two handlers for the two hierarchical
3063     context entities.
3064     To use these handlers, one simply sets the appropriate positions in the
3065     .I mg_ehand
3066     dispatch table to point to these functions.
3067     Additional functions and global data structures provide convenient
3068     access to the relevant contexts, and all of these are detailed in
3069     the following manual pages.
3070     .ds LH Basic Parser Routines
3071     .ds RH MG_INIT
3072     .bp
3073     .SH
3074     NAME
3075     .LP
3076     mg_init, mg_ehand, mg_uhand - initialize MGF entity handlers
3077     .SH
3078     SYNOPSIS
3079     .LP
3080     #include "parser.h"
3081     .LP
3082     .B void
3083     mg_init(
3084     .B void
3085     )
3086     .LP
3087     .B int
3088     mg_defuhand(
3089     .B int
3090     argc,
3091     .B char
3092     **argv )
3093     .LP
3094     .B "extern int"
3095     (*mg_ehand[MG_NENTITIES])(
3096     .B int
3097     argc,
3098     .B char
3099     **argv )
3100     .LP
3101     .B "extern int"
3102     (*mg_uhand)(
3103     .B int
3104     argc,
3105     .B char
3106     **argv )
3107     .LP
3108     .B "extern unsigned"
3109     mg_nunknown
3110     .SH
3111     DESCRIPTION
3112     .LP
3113     The parser dispatch table,
3114     .I mg_ehand
3115     is initially set to all NULL pointers, and it
3116     is the duty of the calling program to assign entity handler functions to
3117     each of the supported entity positions in the array.
3118     The entities are given in the include file "parser.h" as the
3119     following:
3120     .DS
3121     #define MG_E_COMMENT 0 /* # */
3122     #define MG_E_COLOR 1 /* c */
3123     #define MG_E_CCT 2 /* cct */
3124     #define MG_E_CONE 3 /* cone */
3125     #define MG_E_CMIX 4 /* cmix */
3126     #define MG_E_CSPEC 5 /* cspec */
3127     #define MG_E_CXY 6 /* cxy */
3128 greg 1.4 #define MG_E_CYL 7 /* cyl */
3129 greg 1.1 #define MG_E_ED 8 /* ed */
3130     #define MG_E_FACE 9 /* f */
3131     #define MG_E_INCLUDE 10 /* i */
3132     #define MG_E_IES 11 /* ies */
3133 greg 1.2 #define MG_E_IR 12 /* ir */
3134 greg 1.1 #define MG_E_MATERIAL 13 /* m */
3135     #define MG_E_NORMAL 14 /* n */
3136     #define MG_E_OBJECT 15 /* o */
3137     #define MG_E_POINT 16 /* p */
3138     #define MG_E_PRISM 17 /* prism */
3139     #define MG_E_RD 18 /* rd */
3140     #define MG_E_RING 19 /* ring */
3141     #define MG_E_RS 20 /* rs */
3142     #define MG_E_SIDES 21 /* sides */
3143     #define MG_E_SPH 22 /* sph */
3144     #define MG_E_TD 23 /* td */
3145     #define MG_E_TORUS 24 /* torus */
3146     #define MG_E_TS 25 /* ts */
3147     #define MG_E_VERTEX 26 /* v */
3148     #define MG_E_XF 27 /* xf */
3149    
3150     #define MG_NENTITIES 28 /* total # entities */
3151     .DE
3152     .LP
3153     Once the
3154     .I mg_ehand
3155     array has been set by the program, the
3156     .I mg_init
3157     routine must be called to complete the initialization process.
3158     This should be done once and only once per invocation, before any other
3159     parser routines are called.
3160     .LP
3161     The
3162     .I mg_uhand
3163     variable points to the current handler for unknown entities
3164     encountered on the input.
3165     Its default value points to the
3166     .I mg_defuhand
3167     function, which simply increments the global variable
3168     .I mg_nunknown,
3169     printing a warning message on the standard error on the first
3170     offense.
3171     (This message may be avoided by incrementing
3172     .I mg_nunknown
3173     before processing begins.)\0
3174     If
3175     .I mg_uhand
3176     is assigned a value of NULL, then an unknown entity will return an
3177     .I MG_EUNK
3178     error, which will cause the parser to abort.
3179     (See the
3180     .I mg_load
3181     page for a list of errors.)\0
3182     If the
3183     .I mg_uhand
3184     pointer is assigned to another function, that function will receive
3185     any unknown entities and their arguments, and the parsing will
3186     abort if the new function returns a non-zero error value.
3187     This offers a convenient way to customize the language by adding
3188     non-standard entities.
3189     .SH
3190     DIAGNOSTICS
3191     .LP
3192     If an inconsistent set of entities has been set for support, the
3193     .I mg_init
3194     routine will print an informative message to standard error and abort
3195     the calling program with a call to
3196     .I exit.
3197     This is normally unacceptable behavior for a library routine, but since
3198     such an error indicates a fault with the calling program itself,
3199     recovery is impossible.
3200     .SH
3201     SEE ALSO
3202     .LP
3203     mg_load, mg_handle
3204     .ds RH MG_LOAD
3205     .bp
3206     .SH
3207     NAME
3208     .LP
3209     mg_load, mg_clear, mg_file, mg_err - load MGF file, clear data structures
3210     .SH
3211     SYNOPSIS
3212     .LP
3213     #include "parser.h"
3214     .LP
3215     .B int
3216     mg_load(
3217     .B char
3218     *filename )
3219     .LP
3220     .B void
3221     mg_clear(
3222     .B void
3223     )
3224     .LP
3225     .B extern
3226     MG_FCTXT *mg_file
3227     .LP
3228     .B "extern char"
3229     *mg_err[MG_NERRS]
3230     .SH
3231     DESCRIPTION
3232     .LP
3233     The
3234     .I mg_load
3235     function loads the named file, or standard input if
3236     .I filename
3237     is the NULL pointer.
3238     Calls back to the appropriate MGF handler routines are made through the
3239     .I mg_ehand
3240     dispatch table.
3241     .LP
3242     The global
3243     .I mg_file
3244     variable points to the current file context structure, which
3245     may be useful for the interpretation of certain entities, such as
3246     .UL ies,
3247     which must know the directory path of the enclosing file.
3248     This structure is of the defined type
3249     .I MG_FCTXT,
3250     given in "parser.h" as:
3251     .DS
3252     typedef struct mg_fctxt {
3253     char fname[96]; /* file name */
3254     FILE *fp; /* stream pointer */
3255     int fid; /* unique file context id */
3256     char inpline[4096]; /* input line */
3257     int lineno; /* line number */
3258     struct mg_fctxt *prev; /* previous context */
3259     } MG_FCTXT;
3260     .DE
3261     .SH
3262     DIAGNOSTICS
3263     .LP
3264     If an error is encountered during parsing,
3265     .I mg_load
3266     will print an appropriate error message to the standard error stream
3267     and return one of the non-zero values from "parser.h" listed below:
3268     .DS
3269     #define MG_OK 0 /* normal return value */
3270     #define MG_EUNK 1 /* unknown entity */
3271     #define MG_EARGC 2 /* wrong number of arguments */
3272     #define MG_ETYPE 3 /* argument type error */
3273 greg 1.4 #define MG_EILL 4 /* illegal argument value */
3274 greg 1.1 #define MG_EUNDEF 5 /* undefined reference */
3275     #define MG_ENOFILE 6 /* cannot open input file */
3276     #define MG_EINCL 7 /* error in included file */
3277     #define MG_EMEM 8 /* out of memory */
3278     #define MG_ESEEK 9 /* file seek error */
3279     #define MG_EBADMAT 10 /* bad material specification */
3280 greg 1.8 #define MG_ELINE 11 /* input line too long */
3281 greg 1.1
3282 greg 1.8 #define MG_NERRS 12
3283 greg 1.1 .DE
3284     If it is inappropriate to send output to standard error, the calling
3285     program should use the routines listed under
3286     .I mg_open
3287     for better control over the parsing process.
3288     .LP
3289     The
3290     .I mg_err
3291     array contains error messages corresponding to each of the values
3292     listed above in the native country's language.
3293     .SH
3294     SEE ALSO
3295     .LP
3296 greg 1.4 mg_fgetpos, mg_handle, mg_init, mg_open
3297 greg 1.1 .ds RH MG_OPEN
3298     .bp
3299     .SH
3300     NAME
3301     .LP
3302     mg_open, mg_read, mg_parse, mg_close - MGF file loading subroutines
3303     .SH
3304     SYNOPSIS
3305     .LP
3306     #include "parser.h"
3307     .LP
3308     .B int
3309     mg_open( MG_FCTXT *fcp,
3310     .B char
3311     *filename )
3312     .LP
3313     .B int
3314     mg_read(
3315     .B void
3316     )
3317     .LP
3318     .B int
3319     mg_parse(
3320     .B void
3321     )
3322     .LP
3323     .B void
3324     mg_close(
3325     .B void
3326     )
3327     .SH
3328     DESCRIPTION
3329     .LP
3330     Most loaders and translators will call the
3331     .I mg_load
3332     routine to handle the above operations, but some programs or
3333     entity handlers require tighter control over the loading process.
3334     .LP
3335     The
3336     .I mg_open
3337     routine takes an uninitialized
3338     .I MG_FCTXT
3339     structure and a file name as its arguments.
3340     If
3341     .I filename
3342     is the NULL pointer, the standard input is "opened."
3343     The
3344     .I fcp
3345     structure will be set by
3346     .I mg_open
3347     prior to its return, and the global
3348     .I mg_file
3349     pointer will be assigned to point to it.
3350     This variable must not be destroyed until after the file is closed
3351     with a call to
3352     .I mg_close.
3353     (See the
3354     .I mg_load
3355     page for a definition of
3356     .I mg_file
3357     and the
3358     .I MG_FCTXT
3359     type.)\0
3360     .LP
3361     The
3362     .I mg_read
3363     function reads the next input line from the current file,
3364     returning the number of characters in the line, or zero if the
3365     end of file is reached or there is a file error.
3366 greg 1.8 If the last character read in the input line is not a newline,
3367     then the input line was too long, and you
3368     should return an MG_ELINE error.
3369 greg 1.1 The function skips over escaped newlines, and keeps track of the
3370     line number in the current file context
3371     .I mg_file,
3372     which also contains the line that was read.
3373     .LP
3374     The
3375     .I mg_parse
3376     function breaks the current line in the
3377     .I mg_file
3378     structure into words and calls the appropriate handler routine, if
3379     any.
3380     Blank lines and unsupported entities cause a quick return.
3381     .LP
3382     The
3383     .I mg_close
3384     routine closes the current input file (unless it is the standard
3385     input) and returns to the previous file context (if any).
3386     .SH
3387     DIAGNOSTICS
3388     .LP
3389     The
3390     .I mg_open
3391     function returns
3392     .I MG_OK
3393     (0) normally, or
3394     .I MG_ENOFILE
3395     if the open fails for some reason.
3396     .LP
3397     The
3398     .I mg_parse
3399     function returns
3400     .I MG_OK
3401     if the current line was successfully interpreted, or one of the
3402     defined error values if there is a problem.
3403     (See the
3404     .I mg_load
3405     page for the defined error values.)\0
3406     .SH
3407     SEE ALSO
3408     .LP
3409     mg_fgetpos, mg_handle, mg_init, mg_load
3410     .ds RH MG_FGETPOS
3411     .bp
3412     .SH
3413     NAME
3414     .LP
3415     mg_fgetpos, mg_fgoto - get current file position and seek to pointer
3416     .SH
3417     SYNOPSIS
3418     .LP
3419     #include "parser.h"
3420     .LP
3421     .B void
3422     mg_fgetpos( MG_FPOS *pos )
3423     .LP
3424     .B int
3425     mg_fgoto( MG_FPOS *pos )
3426     .SH
3427     DESCRIPTION
3428     .LP
3429     The
3430     .I mg_fgetpos
3431     gets the current MGF file position and loads it into the passed
3432     .I MG_FPOS
3433     structure,
3434     .I pos.
3435     .LP
3436     The
3437     .I mg_fgoto
3438     function seeks to the position
3439     .I pos,
3440     taken from a previous call to
3441     .I mg_fgetpos.
3442     .SH
3443     DIAGNOSTICS
3444     .LP
3445     If
3446     .I mg_fgoto
3447     is passed an illegal pointer or one that does not correspond to the
3448     current
3449     .I mg_file
3450     context, it will return the
3451     .I MG_ESEEK
3452     error value.
3453     Normally, it returns
3454     .I MG_OK
3455     (0).
3456     .SH
3457     SEE ALSO
3458     .LP
3459     mg_load, mg_open
3460     .ds RH MG_HANDLE
3461     .bp
3462     .SH
3463     NAME
3464     .LP
3465     mg_handle, mg_entity, mg_ename, mg_nqcdivs - entity assistance and control
3466     .SH
3467     SYNOPSIS
3468     .LP
3469     .B int
3470     mg_handle(
3471     .B int
3472     en,
3473     .B int
3474     ac,
3475     .B char
3476     *av )
3477     .LP
3478     .B int
3479     mg_entity(
3480     .B char
3481     *name )
3482     .LP
3483     .B "extern char"
3484     mg_ename[MG_NENTITIES][MG_MAXELEN]
3485     .LP
3486     .B "extern int"
3487     mg_nqcdivs
3488     .SH
3489     DESCRIPTION
3490     .LP
3491     The
3492     .I mg_handle
3493     routine may be used to pass entities back to the parser
3494     to be redirected through the
3495     .I mg_ehand
3496     dispatch table.
3497     This method is recommended rather than calling through
3498     .I mg_ehand
3499     directly, since the parser sometimes has its own support routines
3500     that it needs to call for specific entities.
3501     The first argument,
3502     .I en,
3503     is the corresponding entity number, or -1 if
3504     .I mg_handle
3505     should figure it out from the first
3506     .I av
3507     argument.
3508     .LP
3509     The
3510     .I mg_entity
3511     function gets an entity number from its name, using a hash
3512     table on the
3513     .I mg_ename
3514     list.
3515     .LP
3516     The
3517     .I mg_ename
3518     table contains the string names corresponding to each MGF entity in
3519     the designated order.
3520     (See the
3521     .I mg_init
3522     page for the list of MGF entities.)\0
3523     .LP
3524     The global integer variable
3525     .I mg_nqcdivs
3526     tells the parser how many subdivisions to use per quarter circle (90
3527     degrees) when tesselating curved geometry.
3528     The default value is 5, and it may be reset at any time by the
3529     calling program.
3530     .SH
3531     DIAGNOSTICS
3532     .LP
3533     The
3534     .I mg_handle
3535     function returns
3536     .I MG_OK
3537     if the entity is handled correctly, or one of the predefined error
3538     values if there is a problem.
3539     (See the
3540     .I mg_load
3541     page for a list of error values.)\0
3542     .LP
3543     The
3544     .I mg_entity
3545     function returns -1 if the passed name does not appear in the
3546     .I mg_ename
3547     list.
3548     .SH
3549     SEE ALSO
3550     .LP
3551     mg_init, mg_load, mg_open
3552     .ds RH ISINT, ISFLT, ISNAME
3553     .bp
3554     .SH
3555     NAME
3556     .LP
3557     isint, isflt, isname - determine if string fits integer or real format,
3558     or is legal identifier
3559     .SH
3560     SYNOPSIS
3561     .LP
3562     .B int
3563     isint(
3564     .B char
3565     *str )
3566     .LP
3567     .B int
3568     isflt(
3569     .B char
3570     *str )
3571     .LP
3572     .B int
3573     isname(
3574     .B char
3575     *str )
3576     .SH
3577     DESCRIPTION
3578     .LP
3579     The
3580     .I isint
3581     function checks to see if the passed string
3582     .I str
3583     matches a decimal integer format (positive or negative),
3584     and returns 1 or 0 based on whether it does or does not.
3585     .LP
3586     The
3587     .I isflt
3588     function checks to see if the passed string
3589     .I str
3590     matches a floating point format (positive or negative with optional
3591     exponent), and returns 1 or 0 based on whether it does or does not.
3592     .LP
3593     The
3594     .I isname
3595     function checks to see if the passed string
3596     .I str
3597     is a legal identifier name.
3598     In MGF, a legal identifier must begin with a letter and contain only
3599     visible ASCII characters (those between decimal 33 and 127 inclusive).
3600     The one caveat to this is that names may begin with one or more
3601     underscores ('_'), but this is a trick employed by the parser to
3602     maintain a separate name space from the user, and is not legal usage
3603     otherwise.
3604     .LP
3605     Note that a string that matches an integer format is also a valid
3606     floating point value.
3607     Conversely, a string that is not a floating point number cannot be a
3608     valid integer.
3609     .LP
3610     These routines are useful for checking arguments passed to entity
3611     handlers that certain types in certain positions.
3612     If an invalid argument is passed, the handler should return an
3613     .I MG_ETYPE
3614     error.
3615     .SH
3616     SEE ALSO
3617     .LP
3618     mg_init, mg_load
3619     .ds LH Entity Support Routines
3620     .ds RH C_HVERTEX
3621     .bp
3622     .SH
3623     NAME
3624     .LP
3625     c_hvertex, c_getvert, c_cvname, c_cvertex - vertex entity support
3626     .SH
3627     SYNOPSIS
3628     .LP
3629     #include "parser.h"
3630     .LP
3631     .B int
3632     c_hvertex(
3633     .B int
3634     argc,
3635     .B char
3636     **argv )
3637     .LP
3638     C_VERTEX *c_getvert(
3639     .B char
3640     *name )
3641     .LP
3642     .B "extern char"
3643     *c_vname
3644     .LP
3645     .B extern
3646     C_VERTEX *c_cvertex
3647     .SH
3648     DESCRIPTION
3649     .LP
3650     The
3651     .I c_hvertex
3652     function handles the MGF vertex entities,
3653     .UL v,
3654     .UL p
3655     and
3656     .UL n.
3657     If either
3658     .UL p
3659     or
3660     .UL n
3661     is supported, then
3662     .UL v
3663     must be also.
3664     The assignments are normally made to the
3665     .I mg_ehand
3666     array prior to parser initialization, like so:
3667     .DS
3668     mg_ehand[MG_E_VERTEX] = c_hvertex; /* support "v" entity */
3669     mg_ehand[MG_E_POINT] = c_hvertex; /* support "p" entity */
3670     mg_ehand[MG_E_NORMAL] = c_hvertex; /* support "n" entity */
3671     /* other entity handler assignments... */
3672     mg_init(); /* initialize parser */
3673     .DE
3674     If vertex normals are not understood by any of the program-supported
3675     entities, then the
3676     .I MG_E_NORMAL
3677     entry may be left with its original NULL assignment.
3678     .LP
3679     The
3680     .I c_getvert
3681     call takes the name of a defined vertex and returns a pointer to its
3682     .I C_VERTEX
3683     structure, defined in "parser.h" as:
3684     .DS
3685     typedef FLOAT FVECT[3]; /* a 3-d real vector */
3686    
3687     typedef struct {
3688     int clock; /* incremented each change -- resettable */
3689     FVECT p, n; /* point and normal */
3690     } C_VERTEX; /* vertex context */
3691     .DE
3692     The
3693     .I clock
3694     member will be incremented each time the value gets changed by a
3695     .UL p
3696     or
3697     .UL n
3698     entity, and may be reset by the controlling program if desired.
3699     This is a convenient way to keep track of whether or not a vertex has
3700     changed since its last use.
3701     To link identical vertices, one must also check that the current
3702     transform has not changed, which is uniquely identified by the
3703     global
3704     .I xf_context->xid
3705     variable, but only if one is using the parser libraries transform
3706     handler.
3707     (See the
3708     .I xf_handler
3709     page.)\0
3710     .LP
3711     It is possible but not recommended to alter the contents of the
3712     vertex structure returned by
3713     .I c_getvert.
3714     Normally it is read during the
3715     interpretation of entities using named vertices.
3716     .LP
3717     The name of the current vertex is given by the global
3718     .I c_cvname
3719     variable, which is set to NULL if the unnamed vertex is current.
3720     The current vertex value is pointed to by the global variable
3721     .I c_cvertex,
3722     which should never be NULL.
3723     .SH
3724     DIAGNOSTICS
3725     .LP
3726     The
3727     .I c_hvertex
3728     function returns
3729     .I MG_OK
3730     (0) if the vertex is handled correctly, or one of the predefined
3731     error values if there is a problem.
3732     (See the
3733     .I mg_load
3734     page for a list of errors.)\0
3735     .LP
3736     The
3737     .I c_getvert
3738     function returns NULL if the specified vertex name is undefined, at
3739     which point the calling function should return an
3740     .I MG_EUNDEF
3741     error.
3742     .SH
3743     SEE ALSO
3744     .LP
3745     c_hcolor, c_hmaterial, mg_init, mg_load, xf_handler
3746     .ds RH C_HCOLOR
3747     .bp
3748     .SH
3749     NAME
3750     .LP
3751     c_hcolor, c_getcolor, c_ccname, c_ccolor, c_ccvt, c_isgrey -
3752     color entity support
3753     .SH
3754     SYNOPSIS
3755     .LP
3756     #include "parser.h"
3757     .LP
3758     .B int
3759     c_hcolor(
3760     .B int
3761     argc,
3762     .B char
3763     **argv )
3764     .LP
3765     C_COLOR *c_getcolor(
3766     .B char
3767     *name )
3768     .LP
3769     .B "extern char"
3770     *c_ccname
3771     .LP
3772     .B extern
3773     C_COLOR *c_ccolor
3774     .LP
3775     .B void
3776     c_ccvt( C_COLOR *cvp,
3777     .B int
3778     cflags )
3779     .LP
3780     .B int
3781     c_isgrey( C_COLOR *cvp )
3782     .SH
3783     DESCRIPTION
3784     .LP
3785     The
3786     .I c_hcolor
3787     function supports the MGF entities,
3788     .UL c,
3789     .UL cxy,
3790     .UL cspec,
3791     .UL cct
3792     and
3793     .UL cmix.
3794     It is an error to support any of the color field entities without
3795     supporting the
3796     .UL c
3797     entity itself.
3798     The assignments are normally made to the
3799     .I mg_ehand
3800     array prior to parser initialization, like so:
3801     .DS
3802     mg_ehand[MG_E_COLOR] = c_hcolor; /* support "c" entity */
3803     mg_ehand[MG_E_CXY] = c_hcolor; /* support "cxy" entity */
3804     mg_ehand[MG_E_CSPEC] = c_hcolor; /* support "cspec" entity */
3805     mg_ehand[MG_E_CCT] = c_hcolor; /* support "cct" entity */
3806     mg_ehand[MG_E_CMIX] = c_hcolor; /* support "cmix" entity */
3807     /* other entity handler assignments... */
3808     mg_init(); /* initialize parser */
3809     .DE
3810     If the loader/translator has no use for spectral data, the entries for
3811     .UL cspec
3812     and
3813     .UL cct
3814     may be left with their original NULL assignments and these entities will
3815     be re-expressed appropriately as tristimulus values.
3816     .LP
3817     The
3818     .I c_getcolor
3819     function takes the name of a defined color and returns a pointer to its
3820     .I C_COLOR
3821     structure, defined in "parser.h" as:
3822     .DS
3823     #define C_CMINWL 380 /* minimum wavelength */
3824     #define C_CMAXWL 780 /* maximum wavelength */
3825     #define C_CNSS 41 /* number of spectral samples */
3826     #define C_CWLI ((C_CMAXWL-C_CMINWL)/(C_CNSS-1))
3827     #define C_CMAXV 10000 /* nominal maximum sample value */
3828     #define C_CLPWM (683./C_CMAXV) /* peak lumens/watt multiplier */
3829    
3830     typedef struct {
3831     int clock; /* incremented each change */
3832     short flags; /* what's been set */
3833     short ssamp[C_CNSS]; /* spectral samples, min wl to max */
3834     long ssum; /* straight sum of spectral values */
3835     float cx, cy; /* xy chromaticity value */
3836     float eff; /* efficacy (lumens/watt) */
3837     } C_COLOR; /* color context */
3838     .DE
3839     The
3840     .I clock
3841     member will be incremented each time the value gets changed by a
3842     color field entity, and may be reset by the calling program if
3843     desired.
3844     This is a convenient way to keep track of whether or not a color has
3845     changed since its last use.
3846     The
3847     .I flags
3848     member indicates which color representations have been assigned,
3849     and is an inclusive OR of one or more of the following:
3850     .DS
3851     #define C_CSSPEC 01 /* flag if spectrum is set */
3852     #define C_CDSPEC 02 /* flag if defined w/ spectrum */
3853     #define C_CSXY 04 /* flag if xy is set */
3854     #define C_CDXY 010 /* flag if defined w/ xy */
3855     #define C_CSEFF 020 /* flag if efficacy set */
3856     .DE
3857     .LP
3858     It is possible but not recommended to alter the contents of the
3859     color structure returned by
3860     .I c_getcolor.
3861     Normally, this routine is never called directly, since there are no
3862     entities that access colors by name other than
3863     .UL c.
3864     .LP
3865     The global variable
3866     .I c_ccname
3867     points to the name of the current color, or NULL if it is unnamed.
3868     The variable
3869     .I c_ccolor
3870     points to the current color value, which should never be NULL.
3871     .LP
3872     The
3873     .I c_ccvt
3874     routine takes a
3875     .I C_COLOR
3876     structure and a set of desired flag settings and computes the
3877     missing color representation(s).
3878     .LP
3879     The
3880     .I c_isgrey
3881     function returns 1 if the passed color is very close to neutral
3882     grey, or 0 otherwise.
3883     .SH
3884     DIAGNOSTICS
3885     .LP
3886     The
3887     .I c_hcolor
3888     function returns
3889     .I MG_OK
3890     (0) if the color is handled correctly, or one of the predefined
3891     error values if there is a problem.
3892     (See the
3893     .I mg_load
3894     page for a list of errors.)\0
3895     .LP
3896     The
3897     .I c_getcolor
3898     function returns NULL if the specified color name is undefined, at
3899     which point the calling function should return an
3900     .I MG_EUNDEF
3901     error.
3902     .SH
3903     SEE ALSO
3904     .LP
3905     c_hmaterial, c_hvertex, mg_init, mg_load
3906     .ds RH C_HMATERIAL
3907     .bp
3908     .SH
3909     NAME
3910     .LP
3911     c_hmaterial, c_getmaterial, c_cmname, c_cmaterial -
3912     material entity support
3913     .SH
3914     SYNOPSIS
3915     .LP
3916     #include "parser.h"
3917     .LP
3918     .B int
3919     c_hmaterial(
3920     .B int
3921     argc,
3922     .B char
3923     **argv )
3924     .LP
3925     C_MATERIAL *c_getmaterial(
3926     .B char
3927     *name )
3928     .LP
3929     .B "extern char"
3930     *c_cmname
3931     .LP
3932     .B extern
3933     C_MATERIAL *c_cmaterial
3934     .SH
3935     DESCRIPTION
3936     .LP
3937     The
3938     .I c_hmaterial
3939     function supports the MGF entities,
3940     .UL m,
3941     .UL ed,
3942     .UL ir,
3943     .UL rd,
3944     .UL rs,
3945     .UL sides,
3946     .UL td,
3947     and
3948     .UL ts.
3949     It is an error to support any of the material field entities without
3950     supporting the
3951     .UL m
3952     entity itself.
3953     The assignments are normally made to the
3954     .I mg_ehand
3955     array prior to parser initialization, like so:
3956     .DS
3957     mg_ehand[MG_E_MATERIAL] = c_hmaterial; /* support "m" entity */
3958     mg_ehand[MG_E_ED] = c_hmaterial; /* support "ed" entity */
3959     mg_ehand[MG_E_IR] = c_hmaterial; /* support "ir" entity */
3960     mg_ehand[MG_E_RD] = c_hmaterial; /* support "rd" entity */
3961     mg_ehand[MG_E_RS] = c_hmaterial; /* support "rs" entity */
3962     mg_ehand[MG_E_SIDES] = c_hmaterial; /* support "sides" entity */
3963     mg_ehand[MG_E_TD] = c_hmaterial; /* support "td" entity */
3964     mg_ehand[MG_E_TS] = c_hmaterial; /* support "ts" entity */
3965     /* other entity handler assignments... */
3966     mg_init(); /* initialize parser */
3967     .DE
3968     Any of the above entities besides
3969     .UL m
3970     may be unsupported, but the parser will not attempt to include their
3971     effect into other members, e.g. an unsupported
3972     .UL rs
3973     component will not be added back into the
3974     .UL rd
3975     member.
3976     It is therefore safer to support all of the relevant material
3977     entities and make final approximations from the complete
3978     .I C_MATERIAL
3979     structure.
3980     .LP
3981     The
3982     .I c_getmaterial
3983     function takes the name of a defined material and returns a pointer to its
3984     .I C_MATERIAL
3985     structure, defined in "parser.h" as:
3986     .DS
3987     #define C_1SIDEDTHICK 0.005 /* assumed thickness of 1-sided mat. */
3988    
3989     typedef struct {
3990     int clock; /* incremented each change -- resettable */
3991     int sided; /* 1 if surface is 1-sided, 0 for 2-sided */
3992     float nr, ni; /* index of refraction, real and imaginary */
3993     float rd; /* diffuse reflectance */
3994     C_COLOR rd_c; /* diffuse reflectance color */
3995     float td; /* diffuse transmittance */
3996     C_COLOR td_c; /* diffuse transmittance color */
3997     float ed; /* diffuse emittance */
3998     C_COLOR ed_c; /* diffuse emittance color */
3999     float rs; /* specular reflectance */
4000     C_COLOR rs_c; /* specular reflectance color */
4001     float rs_a; /* specular reflectance roughness */
4002     float ts; /* specular transmittance */
4003     C_COLOR ts_c; /* specular transmittance color */
4004     float ts_a; /* specular transmittance roughness */
4005     } C_MATERIAL; /* material context */
4006     .DE
4007     The
4008     .I clock
4009     member will be incremented each time the value gets changed by a
4010     material field entity, and may be reset by the calling program if
4011     desired.
4012     This is a convenient way to keep track of whether or not a material has
4013     changed since its last use.
4014     .LP
4015     All reflectance and transmittance values correspond to normal
4016     incidence, and may vary as a function of angle depending on the
4017     index of refraction.
4018     A solid object is normally represented with a one-sided material.
4019     A two-sided material is most appropriate for thin surfaces, though
4020     it may be used also when the surface normal orientations in a model
4021     are unreliable.
4022     .LP
4023     If a transparent or translucent surface is one-sided, then the
4024     absorption will change as a function of distance through the
4025     material, and a single value for diffuse or specular transmittance is
4026     ambiguous.
4027     We therefore define a standard thickness,
4028     .I C_1SIDEDTHICK,
4029     which is the object thickness to which the given values correspond,
4030     so that one may compute the isotropic absorptance of the material.
4031     .LP
4032     It is possible but not recommended to alter the contents of the
4033     material structure returned by
4034     .I c_getmaterial.
4035     Normally, this routine is never called directly, since there are no
4036     entities that access materials by name other than
4037     .UL m.
4038     .LP
4039     The global variable
4040     .I c_cmname
4041     points to the name of the current material, or NULL if it is unnamed.
4042     The variable
4043     .I c_cmaterial
4044     points to the current material value, which should never be NULL.
4045     .SH
4046     DIAGNOSTICS
4047     .LP
4048     The
4049     .I c_hmaterial
4050     function returns
4051     .I MG_OK
4052     (0) if the color is handled correctly, or one of the predefined
4053     error values if there is a problem.
4054     (See the
4055     .I mg_load
4056     page for a list of errors.)\0
4057     .LP
4058     The
4059     .I c_getmaterial
4060     function returns NULL if the specified material name is undefined, at
4061     which point the calling function should return an
4062     .I MG_EUNDEF
4063     error.
4064     .SH
4065     SEE ALSO
4066     .LP
4067     c_hcolor, c_hvertex, mg_init, mg_load
4068     .ds RH OBJ_HANDLER
4069     .bp
4070     .SH
4071     NAME
4072     .LP
4073     obj_handler, obj_clear, obj_nnames, obj_name - object name support
4074     .SH
4075     SYNOPSIS
4076     .LP
4077     .B int
4078     obj_handler(
4079     .B int
4080     argc,
4081     .B char
4082     **argv )
4083     .LP
4084     .B void
4085     obj_clear(
4086     .B void
4087     )
4088     .LP
4089     .B "extern int"
4090     obj_nnames
4091     .LP
4092     .B "extern char"
4093     **obj_name
4094     .SH
4095     DESCRIPTION
4096     .LP
4097     The
4098     .I obj_handler
4099     routine should be assigned to the
4100     .I MG_E_OBJECT
4101     entry of the parser's
4102     .I mg_ehand
4103     array prior to calling
4104     .I mg_load
4105     if the loader/translator wishes to support hierarchical object
4106     names.
4107     .LP
4108     The
4109     .I obj_clear
4110     function may be used to clear the object name stack and free any
4111     associated memory, but this is usually not necessary since
4112     .UL o
4113     begin and end entities are normally balanced in the input.
4114     .LP
4115     The global
4116     .I obj_nnames
4117     variable indicates the number of names currently in the object
4118     stack, and the
4119     .I obj_name
4120     list contains the name strings in the same order as they were
4121     encountered on the input.
4122     (I.e. the most recently pushed name is last.)\0
4123     .SH
4124     DIAGNOSTICS
4125     .LP
4126     The
4127     .I obj_handler
4128     function returns
4129     .I MG_OK
4130     (0) if the color is handled correctly, or one of the predefined
4131     error values if there is a problem.
4132     (See the
4133     .I mg_load
4134     page for a list of errors.)\0
4135     .SH
4136     SEE ALSO
4137     .LP
4138     mg_init, mg_load, xf_handler
4139     .ds RH XF_HANDLER
4140     .bp
4141     .SH
4142     NAME
4143     .LP
4144     xf_handler, xf_clear, xf_context, xf_argend - transformation support
4145     .SH
4146     SYNOPSIS
4147     .LP
4148     .B int
4149     xf_handler(
4150     .B int
4151     argc,
4152     .B char
4153     **argv )
4154     .LP
4155     .B void
4156     xf_clear(
4157     .B void
4158     )
4159     .LP
4160     .B extern
4161     XF_SPEC *xf_context
4162     .LP
4163     .B "extern char"
4164     **xf_argend
4165     .SH
4166     DESCRIPTION
4167     .LP
4168     The
4169     .I xf_handler
4170     routine should be assigned to the
4171     .I MG_E_XF
4172     entry of the parser's
4173     .I mg_ehand
4174     array prior to calling
4175     .I mg_load
4176     if the loader/translator wishes to support hierarchical
4177     transformations.
4178     (Note that all MGF geometric entities require this support.)\0
4179     .LP
4180     The
4181     .I xf_clear
4182     function may be used to clear the transform stack and free any
4183     associated memory, but this is usually not necessary since
4184     .UL xf
4185     begin and end entities are normally balanced in the input.
4186     .LP
4187     The global
4188     .I xf_context
4189     variable points to the current transformation context, which is of
4190     the type
4191     .I XF_SPEC,
4192     described in "parser.h":
4193     .DS
4194     typedef struct xf_spec {
4195     long xid; /* unique transform id */
4196     short xac; /* context argument count */
4197     short rev; /* boolean true if vertices reversed */
4198     XF xf; /* cumulative transformation */
4199     struct xf_array *xarr; /* transformation array pointer */
4200     struct xf_spec *prev; /* previous transformation context */
4201     } XF_SPEC; /* followed by argument buffer */
4202     .DE
4203     The
4204     .I xid
4205     member is a identifier associated with this transformation,
4206     which should be the same for identical transformations, as an aid to
4207     vertex sharing.
4208     (See also the
4209     .I c_hvertex
4210     page.)\0
4211     The
4212     .I xac
4213     member indicates the total number of transform arguments, and is
4214     used to indicate the position of the first argument relative to the
4215     last one pointed to by the global
4216     .I xf_argend
4217     variable.
4218     .LP
4219     The first transform argument starts at
4220     .I xf_argv,
4221     which is a macro defined in "parser.h" as:
4222     .DS
4223     #define xf_argv (xf_argend - xf_context->xac)
4224     .DE
4225     Note that accessing this macro will result in a segmentation violation
4226     if the current context is NULL, so one should first test the second macro
4227     .I xf_argc
4228     against zero.
4229     This macro is defined as:
4230     .DS
4231     #define xf_argc (xf_context==NULL ? 0 : xf_context->xac)
4232     .DE
4233     .LP
4234     Normally, neither of these macros will be used, since there are
4235     routines for transforming points, vectors and scalars directly based
4236     on the current transformation context.
4237     (See the
4238     .I xf_xfmpoint
4239     page for details.)\0
4240     .LP
4241     The
4242     .I rev
4243     member of the
4244     .I XF_SPEC
4245     structure indicates whether or not this transform reverses the order
4246     of polygon vertices.
4247     This member will be 1 if the transformation mirrors about an odd
4248     number of coordinate axes, thus inverting faces.
4249     The usual thing to do in this circumstance is to interpret the
4250     vertex arguments in the reverse order, so as to bring the face back
4251     to its original orientation in the new position.
4252     .LP
4253     The
4254     .I xf
4255     member contains the transformation scalefactor (in xf.sca)
4256     and 4x4 homogeneous matrix (in xf.xfm), but these will usually not
4257     be accessed directly.
4258     Likewise, the
4259     .I xarr
4260     and
4261     .I prev
4262     members point to data that should not be needed by the calling
4263     program.
4264     .SH
4265     DIAGNOSTICS
4266     .LP
4267     The
4268     .I xf_handler
4269     function returns
4270     .I MG_OK
4271     (0) if the color is handled correctly, or one of the predefined
4272     error values if there is a problem.
4273     (See the
4274     .I mg_load
4275     page for a list of errors.)\0
4276     .SH
4277     SEE ALSO
4278     .LP
4279     mg_init, mg_load, obj_handler, xf_xfmpoint
4280     .ds RH XF_XFMPOINT
4281     .bp
4282     .SH
4283     NAME
4284     .LP
4285 greg 1.3 xf_xfmpoint, xf_xfmvect, xf_rotvect, xf_scale - apply current
4286 greg 1.1 transformation
4287     .SH
4288     SYNOPSIS
4289     .LP
4290     .B void
4291     xf_xfmpoint( FVECT pnew, FVECT pold )
4292     .LP
4293     .B void
4294     xf_xfmvect( FVECT vnew, FVECT vold )
4295     .LP
4296     .B void
4297     xf_rotvect( FVECT nnew, FVECT nold )
4298     .LP
4299     .B double
4300     xf_scale(
4301     .B double
4302     sold )
4303     .SH
4304     DESCRIPTION
4305     .LP
4306     The
4307     .I xf_xfmpoint
4308     routine applies the current transformation defined by
4309     .I xf_context
4310     to the point
4311     .I pold,
4312     scaling, rotating and moving it to its proper location, which is put in
4313     .I pnew.
4314 greg 1.2 (As for
4315     .I xf_xfmvect
4316     and
4317     .I xf_rotvect,
4318     the two arguments may point to the same vector.)\0
4319 greg 1.1 .LP
4320     The
4321     .I xf_xfmvect
4322     routine applies the current transformation to the vector
4323     .I vold,
4324     scaling and rotating it to its proper location, which is put in
4325     .I vnew.
4326     The only difference between
4327     .I xf_xfmpoint
4328     and
4329     .I xf_xfmvect
4330     is that in the latter, the final translation is not applied.
4331     .LP
4332     The
4333     .I xf_rotvect
4334     routine rotates the vector
4335     .I nold
4336     using the current transformation, and stores the result in
4337     .I nnew.
4338     No translation or scaling is applied, which is the appropriate
4339     action for surface normal vectors for example.
4340     .LP
4341     The
4342     .I xf_scale
4343     function takes a scalar argument
4344     .I sold
4345     and applies the current scale factor, returning the result.
4346     .SH
4347     SEE ALSO
4348     .LP
4349     xf_handler
4350     .ds LH
4351     .ds RH
4352     .bp
4353     .NH
4354     Application Notes
4355     .NH 2
4356     Relation to Standard Practices in Computer Graphics
4357     .LP
4358     For those coming from a computer graphics background, some of the
4359     choices in the material model may seem strange or even capricious.
4360     Why not simply stick with RGB colors and a Phong specular component
4361     like everyone else?
4362     What is the point in choosing the number of sides to a material?
4363     .LP
4364     In the real world, a surface can have only one side,
4365     defining the interface between one volume and another.
4366     Many object-space rendering packages (e.g. z-buffer algorithms) take
4367     advantage of this fact by culling back-facing polygons and thus saving
4368     as much as 50% of the preprocessing time.
4369     However, many models rely on an
4370     approximation whereby a single surface is used to represent a very thin
4371     volume, such as a pane of glass, and this also can provide significant
4372     calculational savings in an image-space algorithm (such as
4373     ray-tracing).
4374     Also, many models are created in such a way that the front vs. back
4375     information is lost or confused, so that the back side of one or
4376     more surfaces may have to serve as the front side during rendering.
4377     (AutoCAD is one easily identified culprit in this department.)\0
4378     Since both types of surface models are useful and any
4379     rendering algorithm may ultimately be applied, MGF provides a way
4380     to specify sidedness rather than picking one interpretation or the other.
4381     .LP
4382     The problem with RGB is that there is no accepted standard, and even
4383     if we were to set one it would either be impossible to realize (i.e.
4384     impossible to create phosphors with the chosen colors) or it would
4385     have a gamut that excludes many saturated colors.
4386     The CIE color system was very carefully conceived and developed,
4387     and is the standard to which all photometric measurements adhere.
4388     It is therefore the logical choice in any standard format, though it
4389     has been too often ignored by the computer graphics community.
4390     .LP
4391     Regarding Phong shading, this was never a physical model and making it
4392     behave basic laws of reciprocity and energy balance is difficult.
4393     More to the point, specular power has almost nothing to do with
4394     surface microstructure, and is difficult to set properly
4395     even if every physical characteristic of a material has
4396     been carefully measured.
4397     This is the ultimate indictment of any physical model -- that it
4398     is incapable of reproducing any measurement whatsoever.
4399     .LP
4400     Admittedly, the compliment of diffuse and specular component plus
4401     surface roughness and index of refraction used in MGF is less than a
4402     perfect model, but it is serviceable for most materials and
4403     relatively simple to incorporate into a rendering algorithm.
4404     In the long term, MGF shall probably include full spectral
4405     scattering functions, though the sheer quantity of data involved
4406     makes this burdensome from both the measurement side and the
4407     simulation side.
4408     .NH 3
4409     Converting between Phong Specular Power and Gaussian Roughness
4410     .LP
4411     So-called specular reflection and transmission are modeled using a
4412     Gaussian distribution of surface facets.
4413     The roughness parameters to the
4414     .UL rs
4415     and
4416     .UL ts
4417     entities specify
4418     the root-mean-squared (RMS) surface facet slope, which varies from 0
4419     for a perfectly smooth surface to around .2 for a fairly rough one.
4420     The effect this will have on the reflected component distribution is
4421     well-defined, but predicting the behavior of the transmitted
4422     component requires further assumptions.
4423     We assume that the surface
4424     scatters light passing through it just as much as it scatters
4425     reflected light.
4426     This assumption is approximately correct for a
4427     two-sided transparent material with an index of refraction of 1.5
4428     (like glass) and both sides having the given RMS facet slope.
4429     .LP
4430     Oftentimes, one is translating from a Phong exponent on the cosine
4431     of the half-vector-to-normal angle to the more physical but less
4432     familiar Gaussian model of MGF.
4433     The hardest part is translating the specular power to a roughness value.
4434     For this, we recommend the following approximation:
4435     .IP
4436     roughness = 0.6/sqrt(specular_power)
4437     .LP
4438     It is not a perfect correlation, but it is about as close as one can get.
4439     .NH 3
4440     Converting between RGB and CIE Colors
4441     .LP
4442     Unlike most graphics languages, MGF does not use an RGB color model,
4443     simply because there is no recognized definition for this model.
4444     It is based on computer monitor phosphors, which vary from one
4445     CRT to the next.
4446     (There is an RGB standard defined in the TV
4447     industry, but this has a rather poor correlation to most computer
4448     monitors and it is impossible to express many real-world colors
4449     within its limited gamut.)\0
4450     .LP
4451     MGF uses two alternative, well-defined standards, spectral power
4452     distributions and the 1931 CIE 2 degree standard observer.
4453     With the CIE standard, any viewable
4454     color may be exactly represented as an (x,y) chromaticity value.
4455     Unfortunately, the interaction between
4456     colors (i.e. colored light sources and interreflections) cannot be
4457     specified exactly with any finite coordinate set, including CIE
4458     chromaticities.
4459     So, MGF offers the ability to give reflectance,
4460     transmittance or emittance as a function of wavelength over the visible
4461     spectrum.
4462     This function is still discretized, but at a user-selectable
4463     resolution.
4464     Furthermore, spectral colors may be mixed, providing (nearly)
4465     arbitrary basis functions, which can produce more accurate results in
4466     some cases and are merely a convenience for translation in others.
4467     .LP
4468     Conversion back and forth between CIE chromaticity coordinates and spectral
4469     samples is provided within the MGF parser.
4470     Unfortunately, conversion
4471     to and from RGB values depends on a particular RGB definition, and as we
4472     have said, there is no recognized standard.
4473     We therefore recommend that
4474     you decide yourself what chromaticity values to use for each RGB primary,
4475     and adopt the following code to convert between CIE and RGB coordinates.
4476     .LP
4477     .nf
4478     #ifdef NTSC
4479     #define CIE_x_r 0.670 /* standard NTSC primaries */
4480     #define CIE_y_r 0.330
4481     #define CIE_x_g 0.210
4482     #define CIE_y_g 0.710
4483     #define CIE_x_b 0.140
4484     #define CIE_y_b 0.080
4485     #define CIE_x_w 0.3333 /* monitor white point */
4486     #define CIE_y_w 0.3333
4487     #else
4488     #define CIE_x_r 0.640 /* nominal CRT primaries */
4489     #define CIE_y_r 0.330
4490     #define CIE_x_g 0.290
4491     #define CIE_y_g 0.600
4492     #define CIE_x_b 0.150
4493     #define CIE_y_b 0.060
4494     #define CIE_x_w 0.3333 /* monitor white point */
4495     #define CIE_y_w 0.3333
4496     #endif
4497    
4498 greg 1.4 #define CIE_D ( CIE_x_r*(CIE_y_g - CIE_y_b) + \\
4499     CIE_x_g*(CIE_y_b - CIE_y_r) + \\
4500 greg 1.1 CIE_x_b*(CIE_y_r - CIE_y_g) )
4501 greg 1.4 #define CIE_C_rD ( (1./CIE_y_w) * \\
4502     ( CIE_x_w*(CIE_y_g - CIE_y_b) - \\
4503     CIE_y_w*(CIE_x_g - CIE_x_b) + \\
4504 greg 1.1 CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g ) )
4505 greg 1.4 #define CIE_C_gD ( (1./CIE_y_w) * \\
4506     ( CIE_x_w*(CIE_y_b - CIE_y_r) - \\
4507     CIE_y_w*(CIE_x_b - CIE_x_r) - \\
4508 greg 1.1 CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r ) )
4509 greg 1.4 #define CIE_C_bD ( (1./CIE_y_w) * \\
4510     ( CIE_x_w*(CIE_y_r - CIE_y_g) - \\
4511     CIE_y_w*(CIE_x_r - CIE_x_g) + \\
4512 greg 1.1 CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r ) )
4513    
4514     #define CIE_rf (CIE_y_r*CIE_C_rD/CIE_D)
4515     #define CIE_gf (CIE_y_g*CIE_C_gD/CIE_D)
4516     #define CIE_bf (CIE_y_b*CIE_C_bD/CIE_D)
4517    
4518     float xyz2rgbmat[3][3] = { /* XYZ to RGB */
4519     {(CIE_y_g - CIE_y_b - CIE_x_b*CIE_y_g + CIE_y_b*CIE_x_g)/CIE_C_rD,
4520     (CIE_x_b - CIE_x_g - CIE_x_b*CIE_y_g + CIE_x_g*CIE_y_b)/CIE_C_rD,
4521     (CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g)/CIE_C_rD},
4522     {(CIE_y_b - CIE_y_r - CIE_y_b*CIE_x_r + CIE_y_r*CIE_x_b)/CIE_C_gD,
4523     (CIE_x_r - CIE_x_b - CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r)/CIE_C_gD,
4524     (CIE_x_b*CIE_y_r - CIE_x_r*CIE_y_b)/CIE_C_gD},
4525     {(CIE_y_r - CIE_y_g - CIE_y_r*CIE_x_g + CIE_y_g*CIE_x_r)/CIE_C_bD,
4526     (CIE_x_g - CIE_x_r - CIE_x_g*CIE_y_r + CIE_x_r*CIE_y_g)/CIE_C_bD,
4527     (CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r)/CIE_C_bD}
4528     };
4529    
4530     float rgb2xyzmat[3][3] = { /* RGB to XYZ */
4531     {CIE_x_r*CIE_C_rD/CIE_D,CIE_x_g*CIE_C_gD/CIE_D,CIE_x_b*CIE_C_bD/CIE_D},
4532     {CIE_y_r*CIE_C_rD/CIE_D,CIE_y_g*CIE_C_gD/CIE_D,CIE_y_b*CIE_C_bD/CIE_D},
4533     {(1.-CIE_x_r-CIE_y_r)*CIE_C_rD/CIE_D,
4534     (1.-CIE_x_g-CIE_y_g)*CIE_C_gD/CIE_D,
4535     (1.-CIE_x_b-CIE_y_b)*CIE_C_bD/CIE_D}
4536     };
4537    
4538    
4539     cie_rgb(rgbcolor, ciecolor) /* convert CIE to RGB */
4540     register float *rgbcolor, *ciecolor;
4541     {
4542     register int i;
4543    
4544     for (i = 0; i < 3; i++) {
4545     rgbcolor[i] = xyz2rgbmat[i][0]*ciecolor[0] +
4546     xyz2rgbmat[i][1]*ciecolor[1] +
4547     xyz2rgbmat[i][2]*ciecolor[2] ;
4548     if (rgbcolor[i] < 0.0) /* watch for negative values */
4549     rgbcolor[i] = 0.0;
4550     }
4551     }
4552    
4553    
4554     rgb_cie(ciecolor, rgbcolor) /* convert RGB to CIE */
4555     register float *ciecolor, *rgbcolor;
4556     {
4557     register int i;
4558    
4559     for (i = 0; i < 3; i++)
4560     ciecolor[i] = rgb2xyzmat[i][0]*rgbcolor[0] +
4561     rgb2xyzmat[i][1]*rgbcolor[1] +
4562     rgb2xyzmat[i][2]*rgbcolor[2] ;
4563     }
4564     .fi
4565     .LP
4566     An alternative to adopting the above code is to use the MGF "cmix"
4567     entity to convert from RGB directly by naming the three primaries in
4568     terms of their chromaticities, e.g:
4569     .DS
4570     c R =
4571     cxy 0.640 0.330
4572     c G =
4573     cxy 0.290 0.600
4574     c B =
4575     cxy 0.150 0.060
4576     .DE
4577     .LP
4578     Then, converting from RGB to MGF colors is as simple as multiplying each
4579     component by its relative luminance in a cmix statement, for instance:
4580     .DS
4581     c white =
4582     cmix 0.265 R 0.670 G 0.065 B
4583     .DE
4584     .LP
4585     For the chosen RGB standard, the above specification would result a pure
4586     white.
4587     The reason the coefficients are not all 1 as you might expect is
4588     that cmix uses relative luminance as the standard for its weights.
4589     Since
4590     blue is less luminous for the same energy than red, which is in turn
4591     less luminous than green, the weights cannot be the same to achieve an
4592     even spectral balance.
4593     Unfortunately, computing these relative weights
4594     is not straightforward, though it is given in the above macros as CIE_rf,
4595     CIE_gf and CIE_bf.
4596     (The common factors in these macros may of course
4597     be removed since
4598     .UL cmix
4599     weights are all relative.)\0
4600     Alternatively, one could measure the actual full scale luminance of
4601     the phosphors with a luminance probe and get the same relative
4602     values.
4603     .NH 2
4604     Relation to IESNA LM-63 and Luminaire Catalogs
4605     .LP
4606     Recently, the Illuminating Engineering Society of North America
4607     (IESNA) adopted MGF as the official standard for
4608     representing luminaire geometry and materials.
4609     The way this works in an IES luminaire data file is through the
4610     addition of a keyword called LUMINOUSGEOMETRY, which is given on a
4611     line in the header portion of a file (before the TILT specification)
4612     like so:
4613     .LP
4614     .B [LUMINOUSGEOMETRY]
4615     .I mgf_file
4616     .LP
4617     The given MGF file must exist relative to the directory containing
4618     the IES file (i.e. the same stipulations and restrictions on pathnames
4619     apply as for the MGF
4620     .UL i
4621     entity).
4622     Furthermore, the position of the MGF geometry must be
4623     such that the gross geometric specification of emitting surfaces
4624     in the IES file completely
4625     blocks or encloses the luminous portions of the MGF description.
4626     Specifically, any ray traced towards the MGF geometry must strike
4627     the IES gross geometry before it strikes any luminous surface in the
4628     MGF description.
4629     This provides a convenient way of preventing overcounting in the
4630     illumination calculation, while still allowing for accurate fixture
4631     appearance.
4632     .LP
4633     To give two examples, let us consider first a recessed can, followed
4634     by a hanging direct/indirect fluorescent fixture.
4635     .LP
4636     The most appropriate IES geometric specification for the emitting
4637     area of a can light would be a circular disk.
4638     Since the IES gross geometry gives only the diameter of the disk, the
4639     actual 3-dimensional placement is implicitly defined as having a
4640     center at the origin, with the radiating disk facing in the
4641     negative Z direction (nadir, downwards).
4642     The MGF geometry would then be placed such that any luminous portion
4643     was above this disk, and no portion of it would obstruct the IES
4644     geometry.
4645     The most sensible position therefore has the IES disk flush with the
4646     MGF can opening, as shown in Figure 3.
4647     .bp
4648     Replace this page with the second page from "figures.ps".
4649     .bp
4650     .LP
4651     In the case of a direct/indirect fluorescent fixture, light will
4652     exit both the top and the bottom sides, and the IES geometry must
4653     enclose the radiating portion of the fixture entirely.
4654     It is acceptable to have additional MGF geometry above the
4655     fixture so long as it does not radiate, which is what we must do if
4656     we wish to include the support rods, as shown in Figure 4.
4657     .LP
4658     Note that the origin is always in the exact center of the IES
4659     geometry.
4660     .LP
4661     Not all fixtures will fit the simple IES geometry specification so
4662     nicely.
4663     For odd-shaped fixtures, it may be necessary to use an IES geometry
4664     that does not match the radiating area terribly well in order that
4665     it completely block or enclose the required MGF specification.
4666     .LP
4667     The unit of length in the MGF file is always meters, regardless of
4668     the units specified in the enclosing IES file.
4669     However, any and all multipliers applied to the candlepower data in the
4670     IES file will also be applied to the emittance of surfaces in the
4671     MGF specification, so that one MGF file may serve similar
4672     luminaires that differ in their total output.
4673     .NH
4674     Credits
4675     .LP
4676     The MGF language grew out of a joint investigation into physical
4677     representations for rendering undertaken by the author
4678     (Greg Ward of LBL) and Holly Rushmeier of the National
4679     Institute of Standards and Technology.
4680     After deciding that a complete and robust specification was
4681     an extreme challenge, we shelved the project for another time.
4682     A few months later, the author spoke with Ian Ashdown and Robert
4683     Shakespeare, who are both members of the IES Computing Committee,
4684     about the need for extending the existing data standard to
4685     include luminaire geometry and near-field photometry.
4686     We then moved forward as a team towards a somewhat less ambitious
4687     approach to physical materials and geometry that had the advantage
4688     of simplicity and the possibility of support with a standard parser
4689     library.
4690     The author went to work over the next two months
4691     on the detailed design of the language
4692     and an ANSI-C parser, with regular feedback from the other three
4693     team members.
4694     Several months and several versions later, we arrived at release
4695     1.0, which is the occasion of this document's creation.
4696     .LP
4697     Funding for this work... would be nice.