ImplicitMergeCmdImpl.mesa
Copyright Ó 1989, 1990 by Xerox Corporation. All rights reserved.
Bloomenthal, August 11, 1992 4:02 pm PDT
DIRECTORY Commander, Controls, G3dBasic, G3dControl, ImplicitDefs, ImplicitDesign, ImplicitSurface, RealFns;
ImplicitMergeCmdImpl:
CEDAR
PROGRAM
IMPORTS Controls, G3dControl, ImplicitDesign, ImplicitSurface, RealFns
~
BEGIN
Data:
TYPE ~
RECORD [
tool: ImplicitDesign.Tool ¬ NIL,
rMajor, rMinor, gamma: Controls.Control ¬ NIL,
r, rr, r2, rr2, r4, rr4, a, b, c: REAL ¬ 0.0,
alpha: REAL ¬ 0.0];
MergeCommand: Commander.CommandProc ~ {
d: REF Data ~ NEW[Data];
d.tool ¬ ImplicitDesign.MakeTool[
name: "Merge a torus and a sphere",
startProc: Start,
valueProc: Value,
client: [data: d],
extraControls:
LIST[
d.gamma ¬ Controls.NewControl["Gamma",, d, 0.0, 10.0, 5.0, Radius],
d.rMajor ¬ Controls.NewControl["RMaj",, d,,, 0.1, Radius],
d.rMinor ¬ Controls.NewControl["RMin",, d,,, 0.02, Radius]],
toolSettings: [threshold: 1.0]
];
G3dControl.UpdateControl[d.tool.renderTool.camera, d.tool.renderTool.camera.scale, 5.0];
Setup[d];
};
Radius: Controls.ControlProc ~ {Setup[
NARROW[control.clientData]]};
Setup:
PROC [d:
REF Data] ~ {
d.r ¬ d.rMajor.value; -- radius for sphere, major radius for torus
d.rr ¬ d.rMinor.value;
d.r2 ¬ d.r*d.r;
d.rr2 ¬ d.rr*d.rr;
d.r4 ¬ d.r2*d.r2;
d.rr4 ¬ d.rr2*d.rr2;
d.a ¬ d.r2+d.rr2;
d.b ¬ d.r2-d.rr2;
d.c ¬ d.r2*d.rr2;
};
Value: ImplicitDefs.ValueProc ~ {
d: REF Data ¬ NARROW[clientData];
x2: REAL ~ point.x*point.x;
y2: REAL ~ point.y*point.y;
z2: REAL ~ point.z*point.z;
x2plusy2: REAL ~ x2+y2;
sq: REAL ¬ x2+y2+z2;
t: REAL ¬ -(d.r4+d.rr4+x2*x2+y2*y2+z2*z2+2*(x2*y2+x2plusy2*(z2-d.a)+d.b*z2-d.c));
s: REAL ¬ d.r2-sq;
RETURN[s+d.alpha*(t-s)];
Start: ImplicitDefs.StartProc ~ {
d: REF Data ~ NARROW[clientData];
in: G3dBasic.Triple ¬ [d.r-0.5*d.rr, 0.0, 0.0];
out: G3dBasic.Triple ¬ [d.r+2.0*d.rr, 0.0, 0.0];
t: REAL ¬ IF nFrames < 2 THEN 1.0 ELSE REAL[frame]/REAL[nFrames-1];
d.alpha ¬ 3.0*alpha*alpha-2.0*alpha*alpha*alpha;
d.alpha ¬ MIN[1.0, MAX[0.0, RealFns.Power[t, 1.0/MIN[MAX[d.gamma.value, 0.01], 100.0]]]];
point ¬ ImplicitSurface.SurfacePoint[in, out, Value, d.tool.threshold, d];
};
ImplicitDesign.Register["Merge", MergeCommand, "merge a torus and sphere."];