ImplicitOctree.mesa
Copyright Ó 1985, 1990 by Xerox Corporation. All rights reserved.
Bloomenthal, February 26, 1993 3:03 pm PST
DIRECTORY CedarProcess, Commander, Controls, G3dBasic, G3dOctree, G3dRayTrace, G3dTool, G3dView, Imager, ImplicitDefs, IO, Rope;
ImplicitOctree: CEDAR DEFINITIONS
~ BEGIN
Imported Types
ForkableProc:   TYPE ~ CedarProcess.ForkableProc;
CommandProc:  TYPE ~ Commander.CommandProc;
ButtonList:    TYPE ~ Controls.ButtonList;
ControlList:    TYPE ~ Controls.ControlList;
ControlSizes:   TYPE ~ Controls.ControlSizes;
Segment:     TYPE ~ G3dBasic.Segment;
Triple:     TYPE ~ G3dBasic.Triple;
TripleSequence:   TYPE ~ G3dBasic.TripleSequence;
Octree:     TYPE ~ G3dOctree.Octree;
OctreeType:    TYPE ~ G3dOctree.OctreeType;
Cube:     TYPE ~ G3dOctree.Cube;
CubeSequence:   TYPE ~ G3dOctree.CubeSequence;
DirectionSelect:   TYPE ~ G3dOctree.DirectionSelect;
RayData:    TYPE ~ G3dRayTrace.RayData;
RayProc:    TYPE ~ G3dRayTrace.RayProc;
Client:     TYPE ~ G3dTool.Client;
Tool3d:     TYPE ~ G3dTool.Tool;
CameraRep:   TYPE ~ G3dView.CameraRep;
Context:     TYPE ~ Imager.Context;
ColorProc:    TYPE ~ ImplicitDefs.ColorProc;
CubeOkProc:   TYPE ~ ImplicitDefs.CubeOkProc;
DistanceMode:   TYPE ~ ImplicitDefs.DistanceMode;
DocProc:     TYPE ~ ImplicitDefs.DocProc;
EdgeMode:    TYPE ~ ImplicitDefs.EdgeMode;
NormalProc:    TYPE ~ ImplicitDefs.NormalProc;
PolygonOkProc:   TYPE ~ ImplicitDefs.PolygonOkProc;
StartProc:    TYPE ~ ImplicitDefs.StartProc;
Surface:     TYPE ~ ImplicitDefs.Surface;
TextureProc:    TYPE ~ ImplicitDefs.TextureProc;
Use:      TYPE ~ ImplicitDefs.Use;
ValueProc:    TYPE ~ ImplicitDefs.ValueProc;
VertexOkProc:   TYPE ~ ImplicitDefs.VertexOkProc;
STREAM:     TYPE ~ IO.STREAM;
ROPE:     TYPE ~ Rope.ROPE;
Local Types
AnimationUse:  TYPE ~ {client, surface};
Triangle:    TYPE ~ RECORD [p1, p2, p3: Triple ¬ []];
Tool:     TYPE ~ REF ToolRep;
ToolRep:    TYPE ~ RECORD [
Viewing:
tool3d:     Tool3d ¬ NIL,      -- for line-drawing
destroyed:    BOOL ¬ FALSE,      -- viewer destroyed?
directionSelect:   DirectionSelect ¬ xyz,    -- method of drawing cubes
drawOctree:    BOOL ¬ FALSE,      -- draw the octree?
drawRoots:    BOOL ¬ FALSE,      -- its roots?
drawAge:     BOOL ¬ FALSE,      -- age of cubes?
Hidden Line Elimination:
hleSegment:    Segment ¬ [[], []],     -- for hidden line elimination
hleZStart:     REAL ¬ -0.5,       -- z location of first slice
hleZStop:     REAL ¬ 0.5,       -- z location of last slice
hleZDelta:    REAL ¬ 0.01,       -- distance between the slices
context:     Context ¬ NIL,      -- used for HLE drawing
Modes:
distanceMode:   DistanceMode ¬ inverseSqrd,  -- affect of distance
measureMode:   ATOM ¬ $Unspecified,    -- up to the client
edgeMode:    EdgeMode ¬ binarySectioning, -- mode of edge convergence
Measurement:
tolerance:     REAL ¬ 0.0,       -- nearness tolerance
spread:     REAL ¬ 0.75,       -- radius of influence
threshold:    REAL ¬ 1.0,       -- f'= f-threshold (contour level)
Octree:
octree:     Octree ¬ NIL,      -- the octree
octreeType:    OctreeType ¬ track,     -- method of partitioning
cubeOkProc:    CubeOkProc ¬ NIL,     -- to reject cube when tracking
rootSize:     REAL ¬ 0.5,       -- size of converging octree root
trackSize:     REAL ¬ 0.02,       -- size of tracking cube
delta:      REAL ¬ 0.01,       -- *tracksize = gradient delta
recurseMin:    NAT ¬ 1,        -- min recursion if converging
recurseMax:    NAT ¬ 4,        -- max recursion if converging
adaptAfterMax:   NAT ¬ 0,        -- # levels beyond terminal
adaptDuringMax:  NAT ¬ 0,        -- max # subdiv while tracking
completed:    BOOL ¬ TRUE,      -- if convergence finished
octreeTolerance:   REAL ¬ 0.0001,      -- for edge convergence
flatness:     REAL ¬ 90.0,       -- polygon tolerance in degrees
surfacePoint:    Triple ¬ [0.0, 0.0, 0.0],    -- starting point on the surface
record:     BOOL ¬ FALSE,      -- record the sequence of cubes
The Surface:
docProc:     DocProc ¬ NIL,      -- documents client's object
surface:     Surface ¬ NIL,      -- the surface
Surface Progress:
triangulate:    BOOL ¬ FALSE,      -- triangles or polygons?
roots:      CubeSequence ¬ NIL,    -- progression of octree roots
cubes:      CubeSequence ¬ NIL,    -- progression of tracked cubes
currentCube:    Cube ¬ NIL,       -- current tracked cube
currentTriangle:   Triangle ¬ [],      -- current polygonized triangle
saveShape:    ROPE ¬ NIL,       -- save polys to this file
saveIP:     ROPE ¬ NIL,       -- save line drawing to this file
nImplicitEvaluations: INT ¬ 0,        -- # evaluations for operation
Surface Evaluation Procedures:
startProc:     StartProc ¬ NIL,      -- to find start point
valueProc:    ValueProc ¬ NIL,      -- to evaluate space
vertexOkProc:   VertexOkProc ¬ NIL,    -- to accept/reject vertex
polygonOkProc:   PolygonOkProc ¬ NIL,    -- to accept/reject polygon
normalProc:    NormalProc ¬ NIL,     -- to evaluate surface normal
colorProc:     ColorProc ¬ NIL,      -- to evaluate surface color
textureProc:    TextureProc ¬ NIL,     -- to evaluate surface texture
Ray-tracing:
rayProc:     RayProc ¬ NIL,      -- client supplied ray proc
rayData:     RayData ¬ NIL,      -- ray tracing mechanism
showRayScreen:   BOOL ¬ FALSE,      -- if want ray image screen
showRays:    BOOL ¬ FALSE,      -- if want diagnostic drawing
Animation:
animationUse:   AnimationUse ¬ client,    -- animate client or surface?
animateShapeName:  ROPE ¬ NIL,       -- root for shape file(s)
Client Support:
client:      Client ¬ []        -- client supplied procs and data
];
Implicit Design Tool Creation
MakeTool: PROC [
name:     ROPE,         -- name of the tool
valueProc:   ValueProc,       -- to evaluate implicit function
ops:     G3dTool.Operations ¬ G3dTool.allOps,
extraButtons:   ButtonList ¬ NIL,     -- in addition to the standard set
extraControls:  ControlList ¬ NIL,     -- in addition to the standard set
controlSizes:   ControlSizes ¬ [],     -- adjust size of controls
useArcBalls:   BOOL ¬ TRUE,      -- use arc balls? 
arcBallSize:   INT ¬ 136,
client:     Client ¬ [],       -- client supplied data and procs
graphicsHeight:  INT ¬ 475,
background:   Triple ¬ [0.3, 0.3, 1.0],
noOpen:    BOOL ¬ FALSE,
startProc:    StartProc ¬ NIL,      -- to find start point
cubeOkProc:   CubeOkProc ¬ NIL,     -- to reject cube during tracking
vertexOkProc:  VertexOkProc ¬ NIL,    -- to reject/accept vertex
polygonOkProc:  PolygonOkProc ¬ NIL,    -- to reject/accept polygon
normalProc:   NormalProc ¬ NIL,     -- to evaluate surface normals
colorProc:    ColorProc ¬ NIL,      -- to assign surface vertex color
textureProc:   TextureProc ¬ NIL,     -- to assign surface texture coordinates
rayProc:    RayProc ¬ NIL,      -- to compute pixel value
docProc:    DocProc ¬ NIL,      -- to document the client's object
camera:    CameraRep ¬ [[0,2,0],[],1,60],  -- client can preset camera
nViews:    NAT ¬ 1,        -- number of views
toolSettings:   ToolRep ¬ []]      -- client can preset tool modes
RETURNS [Tool];
Return a tool for manipulation/polygonization/rendering of an implicit design.
Regarding the callback procs:
callbacks may not be nested.
clientData is passed to the callback procs.
If normalProc is NIL, valueProc is used to compute the surface normal.
If textureProc is NIL, no texture is assigned.
If colorProc is NIL, no color is assigned.
The standard set of controls include:
x, y, z global rotations,
viewing scale,
viewing field of view,
adaptive subdivision limit,
polygon flatness limit.
The standard set of buttons include:
measure mode
distance mode
implicit tolerance
implicit threshold
cube size
implicit spread
octree output
polygon output
interpress output
display options
auto polygon save
start
stop.

When ray-tracing, the camera views the ray tracing world, including the object being ray-traced, the image plane, the eye-point and eye-direction, and, optionally, individual rays.
Simple Polygonization
MinPoly: PROC [t: Tool];
Polygonize using the minimal polygonizer.
Complex Surface Operations
Reset: PROC [tool: Tool];
Reset the surface and octree for the implicit tool.
DoMakeOctree: PROC [t: Tool, use: Use ¬ unknown] RETURNS [nImplicitEvaluations: INT];
Create the octree.
DoMakePolygons: PROC [t: Tool, use: Use ¬ unknown] RETURNS [nImplicitEvaluations: INT];
Create the polygons. nImplicitEvaluations does not include edge convergence.
MakeSurface: PROC [
command:    ROPE,         -- e.g., "Grid ND.grid"
out:     STREAM,        -- to which the application can write
measureMode:  ATOM ¬ $Unspecified,    -- client specified measuring mode
distanceMode:  DistanceMode ¬ inverseSqrd,  -- distance mode
tolerance:    REAL ¬ 0.0,       -- error tolerance
spread:    REAL ¬ 0.75,       -- radius of influence
threshold:   REAL ¬ 1.0,       -- threshold (contour level)
octreeType:   OctreeType ¬ track,     -- method of partitioning
rootSize:    REAL ¬ 0.5,       -- size of converging octree root
trackSize:    REAL ¬ 0.02,       -- size of tracking cube
recurseMin:   NAT ¬ 1,        -- min recursion if converging
recurseMax:   NAT ¬ 5,        -- max recursion if converging
adaptAfterMax:  NAT ¬ 0,        -- # levels beyond terminal
adaptDuringMax: NAT ¬ 0,        -- max # subdiv while tracking
octreeTolerance:  REAL ¬ 0.0001,      -- for edge convergence
flatness:    REAL ¬ 30.0,       -- polygons tolerance in degrees
showTool:    BOOL ¬ FALSE]      -- view surface creation
RETURNS [Surface];
Polygonize the implicit surface.
If showTool, the viewer is destroyed upon completion of the surface.
Tool Control
ToolBusy: PROC [tool: Tool] RETURNS [BOOL];
Return true if the tool is currently busy with a forked process.
MaybeFork: PROC [tool: Tool, proc: ForkableProc] RETURNS [forked: BOOL];
Fork the forkable proc if the tool isn't busy; tool is passed to proc as data.
StopTool: PROC [tool: Tool, reason: ROPE ¬ NIL, waitTilAborted: BOOL ¬ FALSE];
This will halt any implicit tool operation and print the reason in the typescript.
Repaint: PROC [tool: Tool, whatChanged: REF ANY ¬ NIL];
Repaint the graphics viewer associated with the tool.
Log-keeping
UpdateLog: PROC [t: Tool, key, entry: ROPE] RETURNS [error: ROPE];
In the log file, if key found, replace its entry; otherwise, add entry under key.
An entry is presumed to occupy a single line of the file.
GetLogEntry: PROC [t: Tool, key: ROPE] RETURNS [entry: ROPE];
Return entry given the key; NIL is returned if no such entry or no such file.
ParametersMessage: PROC [t: Tool] RETURNS [ROPE];
Return a rope describing the parameter settings of the tool.
Registration and Dispatching
Register: PROC [
function: ROPE,     -- name of implicit function
action: CommandProc,   -- proc to be called
doc: ROPE,      -- documentation of function
command: ROPE ¬ NIL];  -- name of CommandTool command (default: "ImplicitDesign")
Register a command proc with ImplicitDesign.
Subsequently, it may be invoked from the commander by "<command> <function>."
ToolOptions: PROC [command: ROPE] RETURNS [toolOptions: ROPE];
Return a rope listing those functions registered under the named command.
ExecuteOption: CommandProc;
Execute the named option; may return [$Failure, "No such option."].
DesignCmd: CommandProc;
The user level command for applications wishing to register under a different command name.
END.