G3dRayTraceToolImpl.mesa
Copyright Ó 1985, 1992 by Xerox Corporation. All rights reserved.
Bloomenthal, October 20, 1992 5:34 pm PDT
DIRECTORY Controls, G3dBasic, G3dMatrix, G3dOctree, G3dRayTrace, G3dRayTraceTool, G3dTool, Icons, Imager, ImagerColor, IO, MessageWindow, Rope, ViewerClasses;
G3dRayTraceToolImpl: CEDAR PROGRAM
IMPORTS Controls, G3dRayTrace, G3dTool, Icons, IO, MessageWindow
EXPORTS G3dRayTraceTool
~ BEGIN
Types
ButtonList:   TYPE ~ Controls.ButtonList;
ControlList:   TYPE ~ Controls.ControlList;
Typescript:   TYPE ~ Controls.Typescript;
DrawProc:   TYPE ~ G3dTool.DrawProc;
RayProc:    TYPE ~ G3dRayTrace.RayProc;
RayData:    TYPE ~ G3dRayTrace.RayData;
RayDataRep:   TYPE ~ G3dRayTrace.RayDataRep;
Tool:     TYPE ~ G3dRayTraceTool.Tool;
ToolRep:    TYPE ~ G3dRayTraceTool.ToolRep;
Triple:    TYPE ~ G3dBasic.Triple;
Matrix:    TYPE ~ G3dMatrix.Matrix;
Context:    TYPE ~ Imager.Context;
ROPE:     TYPE ~ Rope.ROPE;
ClickProc:   TYPE ~ ViewerClasses.ClickProc;
Tool Creation
MakeTool: PUBLIC PROC [
toolName:     ROPE ¬ NIL,
rayProc:     RayProc ¬ NIL,
client:      G3dTool.Client ¬ [],
extraControls:   ControlList ¬ NIL,
extraButtons:    ButtonList ¬ NIL]
RETURNS     [t: Tool]
~ {
t ¬ NEW[ToolRep];
t.rayData ¬ NEW[RayDataRep];
t.rayData.rayProc ¬ rayProc;
IF extraButtons # NIL THEN FOR b: ButtonList ¬ extraButtons, b.rest WHILE b # NIL DO
IF b.first.row = 0 THEN b.first.row ¬ 2;
ENDLOOP;
extraButtons ¬ CONS[Controls.ClickButton["Start", StartButton, t], extraButtons];
extraButtons ¬ CONS[Controls.ClickButton["STOP", StopButton, t], extraButtons];
extraButtons ¬ CONS[Controls.ClickButton["Options", RayTraceOptionsButton, t], extraButtons];
extraButtons ¬ CONS[Controls.ClickButton["Diagnostics", DiagnosticsButton, t], extraButtons];
t.tool3d ¬ G3dTool.MakeTool[
name: toolName,
extraButtons: extraButtons,
extraControls: extraControls,
client: [draw: Draw, destroy: Destroy, data: t],
controlSizes: [20, 200, 60, 20, 60, 150, 150],
graphicsHeight: 200];
};
Destroy: Controls.DestroyProc ~ {
G3dRayTrace.StopRayTracing[NARROW[clientData, Tool].rayData];
};
Tool Options
RayTraceOptionsButton: ClickProc ~ {
t: Tool ¬ NARROW[clientData];
RayTraceOptions[t.rayData, t.tool3d.typescript, DoStart, t];
};
RayTraceOptions: PUBLIC PROC [
r: RayData,
ts: Typescript,
rayTraceProc: PROC [clientData: REF ANY] ¬ NIL,
clientData: REF ANY ¬ NIL]
~ {
V3: PROC [n, d: ROPE, t: Triple] RETURNS [r: Controls.Request] ~ {
r ¬ [IO.PutFLR["%g (now [%g, %g, %g])",
LIST[IO.rope[n],IO.real[t.x],IO.real[t.y],IO.real[t.z]]], d];
};
V2: PROC [n, d: ROPE, n0, n1: NAT] RETURNS [r: Controls.Request] ~ {
r ¬ [IO.PutFR["%g (now [%g, %g])", IO.rope[n], IO.int[n0], IO.int[n1]], d];
};
V: PROC [title, doc: ROPE, value: REAL] RETURNS [Controls.Request] ~ {
RETURN[[IO.PutFR["%g (now %g)", IO.rope[title], IO.real[value]], doc]];
};
SELECT Controls.PopUpRequest[["Ray Trace Options"], LIST[
-- 1 -- ["Reset", "Reset pixel start location to [0, 0]"],
-- 2 -- V2["Pixel location", "Change pixel location", r.nextPixel.x, r.nextPixel.y],
-- 3 -- ["Ray Mode", "Change ray mode"],
-- 4 -- V2["Image width and height", "Change image width and height", r.w, r.h],
-- 5 -- V3["Eye Point", "Change location of eyepoint", r.eyePoint],
-- 6 -- V3["Eye View", "Change direction of eye view", r.eyeView],
-- 7 -- V3["Up Direction", "Change direction of up", r.upDirection],
-- 8 -- V["Field Of View", "Change image field of view", r.fieldOfView],
-- 9 -- ["Lighting", "Change lighting"],
-- 10 -- ["Set specular portion of model"],
-- 11 -- ["RAY TRACE"]]]
FROM
1 => G3dRayTrace.ResetRayTracing[r];
2 => r.nextPixel ¬ Controls.GetIntegerPair[ts, "Pixel location: ", r.nextPixel];
3 => SELECT Controls.PopUpRequest[["Mode"], LIST[
Controls.BoolRequest[r.jitter, "Jitter"],
Controls.BoolRequest[r.noShading, "No Shading"],
["Set Pixel Sub-sampling"],
["Set Adaptive Limit"]]] FROM
1 => r.jitter ¬ NOT r.jitter;
2 => r.noShading ¬ NOT r.noShading;
3 => r.nPixelSamples ¬ Controls.GetNat[ts, "# sub-samples", r.nPixelSamples];
4 => r.adaptiveLimit ¬ Controls.GetNat[ts, "adapt limit", r.adaptiveLimit];
ENDCASE;
4 => {
i: Controls.IntegerPair ¬ Controls.GetIntegerPair[ts, "Width, Height: ", [r.w, r.h]];
r.w ¬ i.x;
r.h ¬ i.y;
G3dRayTrace.ResetRayTracing[r];
};
5 => r.eyePoint ¬ Controls.GetTriple[ts, "EyePoint", r.eyePoint];
6 => r.eyeView ¬ Controls.GetTriple[ts, "EyeView", r.eyeView];
7 => r.upDirection ¬ Controls.GetTriple[ts, "UpDirection", r.upDirection];
8 => r.fieldOfView ¬ Controls.GetReal[ts, "FOV", r.fieldOfView];
9 => r.lights ¬ G3dTool.LightOptions[r.lights, r.eyeView, ts];
10 => r.portionSpecular ¬ Controls.GetReal[ts, "specular: ", r.portionSpecular];
11 => rayTraceProc[clientData];
ENDCASE;
MessageWindow.Append[G3dRayTrace.ParametersMessage[r], TRUE];
};
DiagnosticsButton: ClickProc ~ {
t: Tool ¬ NARROW[clientData];
SELECT Controls.PopUpRequest[["Diagnostics"], LIST[
["Align camera with ray-traced image"],
Controls.BoolRequest[t.showRays, "Diagnostics"]]] FROM
1 => {
t.camera.matrix ¬ G3dView.WorldToViewFromVectors[t.rayData.eyePoint, t.rayData.eyeView, t.rayData.upDirection, t.rayData.fieldOfView, t.camera.matrix];
Repaint[t];
};
2 => t.showRays ¬ NOT t.showRays;
ENDCASE;
};
StartButton: ClickProc ~ {DoStart[clientData]};
DoStart: PROC [clientData: REF ANY] ~ {
G3dRayTrace.StartRayTracing[NARROW[clientData, Tool].rayData];
};
StopButton: ClickProc ~ {
tool: Tool ¬ NARROW[clientData];
TSWrite[tool, " . . . stopped.\n"];
G3dRayTrace.StopRayTracing[tool.rayData];
};
ResetButton: ClickProc ~ {G3dRayTrace.ResetRayTracing[NARROW[clientData, Tool].rayData]};
Tool Display
Repaint: PUBLIC PROC [tool: Tool, whatChanged: REF ANY ¬ NIL] ~ {
G3dTool.Repaint[tool.tool3d];
};
ToolCamera: Controls.ControlProc ~ {
t: Tool ~ NARROW[clientData];
IF control.whatChanged = $TypedIn OR
(control.mouse.button = right AND control.mouse.state # up) THEN Repaint[t];
};
Draw: G3dTool.DrawProc ~ {
t: Tool ¬ NARROW[clientData];
SELECT whatChanged FROM
NIL, $IPOut => G3dRayTrace.DrawRayImageScreen[context, t.rayData, view, vp];
$NewRay => IF t.showRays THEN G3dRayTrace.DrawRayTip[context, t.rayData, view, vp];
ENDCASE => NULL;
};
Tool Support
BadFormat: PROC [ts: Controls.Typescript] ~ {
Controls.TypescriptWrite[ts, ". . . bad format.\n"];
};
Blink: PROC [rope: ROPE] ~ {
MessageWindow.Append[rope, TRUE];
MessageWindow.Blink[];
};
TSWrite: PROC [t: Tool, rope: ROPE] ~ {G3dTool.TSWrite[t.tool3d, rope]};
Start Code
icon: Icons.IconFlavor ¬ Icons.NewIconFromFile["G3dUser.icons", 2];
END.