ImplicitConvolve.mesa
Copyright Ó 1990 by Xerox Corporation. All rights reserved.
Bloomenthal, November 21, 1992 10:15 pm PST
DIRECTORY Commander, Controls, CtBasic, CtFilter, G2dBasic, G3dBasic, G3dDraw, G3dMatrix, G3dPlane, G3dTool, Imager, ImagerColor, ImplicitDefs, ImplicitDesign, IO, Rope;
ImplicitConvolve: CEDAR DEFINITIONS
~ BEGIN
Type Declarations
PixelArray:   TYPE ~ CtBasic.PixelArray;
SampleBuffer:  TYPE ~ CtBasic.SampleBuffer;
SampleMap:   TYPE ~ CtBasic.SampleMap;
Filter:     TYPE ~ CtFilter.Filter;
Pair:     TYPE ~ G2dBasic.Pair;
IntegerPair:   TYPE ~ G2dBasic.IntegerPair;
NatSequence:   TYPE ~ G2dBasic.NatSequence;
Box:     TYPE ~ G3dBasic.Box;
RealSequence:  TYPE ~ G3dBasic.RealSequence;
Quad:     TYPE ~ G3dBasic.Quad;
Triple:    TYPE ~ G3dBasic.Triple;
TripleSequence:  TYPE ~ G3dBasic.TripleSequence;
DrawType:   TYPE ~ G3dDraw.DrawType;
Matrix:    TYPE ~ G3dMatrix.Matrix;
Viewport:    TYPE ~ G3dMatrix.Viewport;
MajorPlane:   TYPE ~ G3dPlane.MajorPlane;
Context:    TYPE ~ Imager.Context;
RGB:     TYPE ~ ImagerColor.RGB;
PairList:    TYPE ~ LIST OF Pair;
TripleList:   TYPE ~ LIST OF Triple;
PrimitiveType:  TYPE ~ {polygon, triangle, line, point};
PrimitiveList:  TYPE ~ LIST OF Primitive;
Thickness:   TYPE ~ REF ThicknessRep;
ThicknessRep:  TYPE ~ RECORD [
value:       REAL ¬ 0.0,     -- thickness of the primitive
array:       PixelArray ¬ NIL,   -- spatial modifier, if non-nil
display:      IntegerPair ¬ [0, 0]    -- pixel array display location
];
Primitive:    TYPE ~ REF PrimitiveRep;
PrimitiveRep:  TYPE ~ RECORD [
id:        INT ¬ -1,      -- mostly for debugging
active:      BOOL ¬ TRUE,    -- FALSE: as if intensity = 0
nVertices:     INTEGER ¬ 0,    -- points.length or indices.length
points:      TripleSequence ¬ NIL,  -- `global' set of vertex locations
indices:      NatSequence ¬ NIL,   -- indices to points/intensities
thickness:     Thickness ¬ NIL,   -- thickness of the primitive
intensities:     RealSequence ¬ NIL,  -- `global' set of vertex intensities
intensity:      REAL ¬ 1.0,     -- flat shaded value or multiplier
valueScale:     REAL ¬ 1.0,     -- derived from intensity
plane:       Quad ¬ [],     -- for polygon
normal:      Triple ¬ [],     -- plane normal
origin:      Triple ¬ [],     -- image alignment origin
xAxis, yAxis:    Triple ¬ [],     -- image alignment axes
p0x, p1x:      Triple ¬ [],     -- for twisted axis
h:        REAL ¬ 0.0,     -- for twisted height
size:       Pair ¬ [0.0, 0.0],    -- size of 3d bounding rectangle
scale:       REAL ¬ 1.0,     -- scale up to image resolution
twist:       Twist ¬ [],     -- normal twist about axis (in radians)
accV:       Triple ¬ [],     -- nearness accelerator for segment
accW:       REAL ¬ 0.0,     -- nearness accelerator for segment
filter:       Filter ¬ [],     -- convolution filter
interp:      BOOL ¬ TRUE,    -- bilinear or linear interpolation
extent:      REAL ¬ 0.1,     -- filter support in world units
bounds:      Box ¬ [],      -- bounding box, for fast cull
recipExtent:     REAL ¬ 10.0,     -- performance accelerator
res:       IntegerPair ¬ [0, 0],   -- pixel array resolution
color:       RGB ¬ [1.0, 1.0, 1.0],  -- color of primitive
path:       PairList ¬ NIL,    -- for image outline
image:      PixelArray ¬ NIL,   -- for 2d convolution of a polygon
buffer:      SampleBuffer ¬ NIL,  -- for 1d convolution of a line
distance:      REAL ¬ 0.0,     -- distance from point to plane
distanceSet:     BOOL ¬ FALSE,    -- if distance valid
display:      IntegerPair ¬ [0, 0]   -- pixel array display location
];
Twist:     TYPE ~ RECORD [
tw0, tw1:      REAL ¬ 0.0,     -- amount of twist in radians
p0, p1:      Triple ¬ []     -- axis endpoints, presumed on poly
];
PrimitiveProc:  TYPE ~ PROC [p: Primitive] RETURNS [continue: BOOL ¬ TRUE];
Operations on Primitives
GetPoint: PROC [p: Primitive, n: INTEGER] RETURNS [Triple];
Return the indexed point from the primitive.
MakePrimitive: PROC [
points:  TripleSequence,
extent:  REAL ¬ 0.1,
thickness: REAL ¬ 0.0,
intensity:  REAL ¬ 1.0,
intensities: RealSequence ¬ NIL,
indices:  LIST OF INTEGER ¬ NIL,
res:   IntegerPair ¬ [50, 50],
color:   RGB ¬ [1.0, 1.0, 1.0],
twist:   Twist ¬ []]
RETURNS [Primitive];
Create a primitive defined by a sequence of 3d planar points.
If intensities # NIL, the primitive is smooth shaded, flat shaded otherwise;
intensity is for flat shading or a multiplier for the individual intensities.
If indices # NIL, it indexes points and (optionally) intensities.
extent is the filter support, in world units.
thickness is the width of the primitive, in world units.
SetGeometry: PROC [p: Primitive];
Set internal geometric attributes of the primitive; this procedure usually not used by clients.
GetImageProjection: PROC [q: Triple, p: Primitive] RETURNS [xy: Pair, distance: REAL];
Project the point onto the primitive. distance is signed.
ValueOfPrimitive: PROC [q: Triple, p: Primitive] RETURNS [REAL];
Compute the implicit value of a primitive given the query point q.
ValueOfPrimitives: PROC [q: Triple, primitives: PrimitiveList] RETURNS [REAL];
Compute the implicit value of the primitives given the query point q.
ConvolvePrimitive: PROC [p: Primitive, filter: BOOL];
Create a planar image at the specified resolution;
if filter, convolve the polygon with a cubic kernel of radius strength.
intensity: 0 = black, 1 = white
SetImagePath: PROC [p: Primitive, path: PairList, filter: BOOL ¬ TRUE];
Set the primitive's image based on the path(s).
The path should be a 2d projection of 3d world points; SetImagePath scales to fit the image.
DisplayPrimitive: PROC [p: Primitive, map: SampleMap];
Display the primitives's 1d, 2d, thickness image(s), on the given map.
GetTwisted: PROC [p: Primitive, q: Triple] RETURNS [Triple];
Return the point q twisted about the axis of p (return q if p.twist not defined).
NActivePrimitives: PROC [primitives: PrimitiveList] RETURNS [INTEGER];
Return the number of active primitives in the list.
SetIDs: PROC [list: LIST OF PrimitiveList, startID: INTEGER ¬ 0];
Assign primitive.id in ascending order.
CombinePrimitives: PROC [list: LIST OF PrimitiveList] RETURNS [PrimitiveList];
Combine arbitrary lists of primitives into a single list.
InvalidateDistance: PROC [primitives: PrimitiveList];
Set primitive.distanceSet FALSE.
InsideSolid: PROC [q: Triple, convexSolid: PrimitiveList] RETURNS [BOOL];
Return TRUE iff point inside all primitive planes.
DrawPrimitive: PROC [
p: Primitive,
context: Context,
view: Matrix,
viewport: Viewport ¬ [],
whatChanged: REF ¬ NIL,
type: DrawType ¬ solid,
log: IO.STREAM ¬ NIL];
Draw the primitive as a polygon onto the given Imager context.
DrawPrimitives: PROC [
list: LIST OF Primitive,
context: Context,
view: Matrix,
viewport: Viewport ¬ [],
whatChanged: REF ¬ NIL,
type: DrawType ¬ solid,
log: IO.STREAM ¬ NIL];
Draw the primitives as polygons onto the given Imager context.
A Design Tool
Tool:  TYPE ~ REF ToolRep;
ToolRep: TYPE ~ RECORD [
cmd:    Commander.Handle ¬ NIL,
tool:    ImplicitDesign.Tool ¬ NIL,
client:    G3dTool.Client ¬ [],
res:    IntegerPair ¬ [50, 50],
filter:    BOOL ¬ TRUE,
interp:   BOOL ¬ TRUE,
primitives:  PrimitiveList ¬ NIL,
convexSolids:  LIST OF PrimitiveList ¬ NIL,
nPrimitives:  INTEGER ¬ 0
];
MakeTool: PUBLIC PROC [
name:    Rope.ROPE ¬ NIL,
primitives:  PrimitiveList ¬ NIL,
convexSolids:  LIST OF PrimitiveList ¬ NIL,
res:    IntegerPair ¬ [50, 50],
client:    G3dTool.Client ¬ [],
ops:    G3dTool.Operations ¬ G3dTool.allOps,
extraControls:  LIST OF Controls.Control ¬ NIL,
extraButtons:  LIST OF Controls.Button ¬ NIL,
controlSizes:  Controls.ControlSizes ¬ [],
useArcBalls:  BOOL ¬ TRUE,
arcBallSize:  INT ¬ 136,
graphicsHeight: INT ¬ 475,
camera:   G3dTool.CameraRep ¬ [[0, 2, 0], [], 1, 60],
background:  Triple ¬ [0.3, 0.3, 1.0],
noOpen:   BOOL ¬ FALSE,
toolSettings:  ImplicitDesign.ToolRep ¬ [],
tool3dSettings: G3dTool.ToolRep ¬ []]
RETURNS [Tool];
DoMakeMaps: PROC [t: Tool];
Convolve and display the primitive maps.
END.