ImplicitDesignCmdsBImpl.mesa
Copyright Ó 1985, 1990 by Xerox Corporation. All rights reserved.
Bloomenthal, August 11, 1992 4:06 pm PDT
DIRECTORY Commander, CommanderOps, Controls, Draw2d, FileNames, G3dBasic, G3dControl, G3dVector, G3dVoxel, ImplicitDefs, ImplicitDesign, ImplicitMisc, ImplicitSurface, IO, Menus, MessageWindow, Rope, ViewerOps;
ImplicitDesignCmdsBImpl: CEDAR PROGRAM
IMPORTS CommanderOps, FileNames, G3dControl, G3dVector, G3dVoxel, ImplicitDesign, ImplicitMisc, ImplicitSurface, IO, MessageWindow, Rope, ViewerOps
~ BEGIN
Types
CommandProc:  TYPE ~ Commander.CommandProc;
ButtonList:   TYPE ~ Controls.ButtonList;
Control:    TYPE ~ Controls.Control;
ControlProc:   TYPE ~ Controls.ControlProc;
OuterData:   TYPE ~ Controls.OuterData;
DrawProc:   TYPE ~ Draw2d.DrawProc;
Pair:     TYPE ~ G3dBasic.Pair;
Triple:    TYPE ~ G3dBasic.Triple;
TripleSequence:  TYPE ~ G3dBasic.TripleSequence;
TripleSequenceRep: TYPE ~ G3dBasic.TripleSequenceRep;
Grid:     TYPE ~ G3dVoxel.Grid;
ClickProc:   TYPE ~ Menus.ClickProc;
ROPE:     TYPE ~ Rope.ROPE;
CubeOkProc:   TYPE ~ ImplicitDefs.CubeOkProc;
StartProc:    TYPE ~ ImplicitDefs.StartProc;
ValueProc:   TYPE ~ ImplicitDefs.ValueProc;
VertexOkProc:  TYPE ~ ImplicitDefs.VertexOkProc;
DocProc:    TYPE ~ ImplicitDesign.DocProc;
Tool:     TYPE ~ ImplicitDesign.Tool;
Grid Design
GridData: TYPE ~ RECORD [grid: Grid, tool: Tool];
GridCommand: CommandProc ~ {
argv: CommanderOps.ArgumentVector ¬ CommanderOps.Parse[cmd];
IF argv.argc # 3
THEN RETURN[$Failure, "Usage: ImplicitDesign Grid <Grid Filename>"]
ELSE {
ENABLE G3dVoxel.Error => IF reason = $NoSuchFile THEN GOTO NoFile;
ReadGrid: PROC RETURNS [grid: G3dVoxel.Grid] ~ {
IO.PutF[cmd.out, "Reading %g . . .", IO.rope[argv[2]]];
grid ¬ G3dVoxel.ReadGridFromFile[FileNames.ResolveRelativePath[argv[2]]];
G3dVoxel.SetGridBox[grid, [[-1.0, -1.0, -1.0], [1.0, 1.0, 1.0]]];
IO.PutRope[cmd.out, " done!\n"];
};
g: Grid ¬ ReadGrid[];
d: REF GridData ¬ NEW[GridData ¬ [grid: g]];
range: Triple ¬ G3dVector.Sub[g.box.max, g.box.min];
size: Triple ¬ G3dVector.DivVectors[range, [REAL[g.res.x], REAL[g.res.y], REAL[g.res.z]]];
d.tool ¬ ImplicitDesign.MakeTool[
name: Rope.Concat["Grid ", argv[2]],
startProc: GridStart,
valueProc: GridValue,
client: [data: d],
toolSettings: [trackSize: MIN[size.x, size.y, size.z]]];
toolSettings: [trackSize: 0.02, threshold: 0.5]];
G3dControl.UpdateControl[d.tool.renderTool.camera, d.tool.renderTool.camera.scale, 2.0/MAX[range.x, range.y, range.z]];
[] ¬ ImplicitDesign.DoMakeOctree[d.tool];
[] ¬ ImplicitDesign.DoMakePolygons[d.tool];
ImplicitMisc.WriteToFile[NIL, d.tool.shape,, TRUE];
ViewerOps.DestroyViewer[d.tool.renderTool.outer];
EXITS NoFile => RETURN[$Failure, "\tno such file"];
};
};
GridValue: ValueProc ~ {
ENABLE G3dVoxel.Error => IF reason = $outOfRange THEN {
corner.outOfRange ¬ TRUE;
CONTINUE;
};
d: REF GridData ¬ NARROW[clientData];
value ¬ G3dVoxel.RetrieveFromGrid[d.grid, point];
};
GridStart: StartProc ~ {
PtVal: TYPE ~ RECORD [pt: Triple, val: REAL];
FindValue: PROC [type: {positive, negative}] RETURNS [ptVal: PtVal] ~ {
FOR i: NAT IN [0..d.grid.res.x) DO
reals2d: G3dVoxel.Reals2d ¬ d.grid.values[i];
FOR j: NAT IN [0..d.grid.res.y) DO
reals: G3dBasic.RealSequence ¬ reals2d[j];
FOR k: NAT IN [0..d.grid.res.z) DO
val: REAL ¬ reals[k];
SELECT type FROM
positive => IF val <= 0.0 THEN LOOP;
ENDCASE => IF val >= 0.0 THEN LOOP;
RETURN[[G3dVoxel.PointFromIJK[d.grid, i, j, k], val]];
ENDLOOP;
ENDLOOP;
REPEAT
FINISHED => ERROR;
ENDLOOP;
};
d: REF GridData ¬ NARROW[clientData];
p: PtVal ¬ FindValue[positive];
n: PtVal ¬ FindValue[negative];
point ¬ ImplicitSurface.SegmentConverge[p.pt, n.pt, p.val, n.val, GridValue, d.tool.threshold, d].point;
};
Solid/Sheet Test
SolidSheetData:  TYPE ~ REF SolidSheetDataRep;
SolidSheetDataRep: TYPE ~ RECORD [
tool:       Tool ¬ NIL
];
SolidSheetCommand: CommandProc ~ {
d: SolidSheetData ¬ NEW[SolidSheetDataRep];
d.tool ¬ ImplicitDesign.MakeTool[
name: "SolidSheet",
startProc: SolidSheetStart,
valueProc: SolidSheetValue,
client: [draw: SolidSheetDraw, data: d]];
};
SolidSheetDraw: DrawProc ~ {d: SolidSheetData ¬ NARROW[clientData];};
SolidSheetValue: ValueProc ~ {d: SolidSheetData ¬ NARROW[clientData];};
SolidSheetStart: StartProc ~ {d: SolidSheetData ¬ NARROW[clientData];};
Support
InBounds: PROC [t: Triple, bound: REAL] RETURNS [ok: BOOL] ~ {
ok ¬ t.x IN [-bound..bound] AND t.y IN [-bound..bound] AND t.z IN [-bound..bound];
};
Blink: PROC [message: ROPE] ~ {
MessageWindow.Append[message, TRUE];
MessageWindow.Blink[];
};
Start Code
ImplicitDesign.Register["SolidSheet", SolidSheetCommand, "explore a solid/sheet."];
ImplicitDesign.Register["Grid", GridCommand, "explore a grid."];
END.