Contours.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Bloomenthal, February 26, 1987 11:43:38 pm PST
DIRECTORY Controls, Imager, ImagerPixelMap, IO, Rope, Vector3d, ViewerClasses;
Types
ROPE: TYPE ~ Rope.ROPE;
STREAM: TYPE ~ IO.STREAM;
Context: TYPE ~ Controls.Context;
Control: TYPE ~ Controls.Control;
Viewer: TYPE ~ ViewerClasses.Viewer;
PixelMap: TYPE ~ ImagerPixelMap.PixelMap;
Rectangle: TYPE ~ Imager.Rectangle;
Color: TYPE ~ Imager.Color;
RealIndex: TYPE ~ RECORD [n: NAT ← 0, alpha: REAL ← 0.0];
Pair: TYPE ~ Vector3d.Pair; -- RECORD [x, y: REAL]
PairSequence: TYPE ~ Vector3d.PairSequence;
PairSequenceRep: TYPE ~ Vector3d.PairSequenceRep;
RealSequence: TYPE ~ Vector3d.RealSequence;
RealSequenceRep: TYPE ~ Vector3d.RealSequenceRep;
Contour: TYPE ~ REF ContourRep;
ContourRep:
TYPE ~
RECORD [
t: REAL ← 0.0, -- curve parameter, if known
closed: BOOL ← FALSE, -- if true, last point connects to 1st
circle: BOOL ← TRUE, -- if true, normals = points
pairs: PairSequence ← NIL, -- 2d points on contour
normals: PairSequence ← NIL, -- 2d normals of contour points
percents: RealSequence ← NIL -- % along contour for each point
];
ContourSequence: TYPE ~ REF ContourSequenceRep;
ContourSequenceRep:
TYPE ~
RECORD [
length: NAT ← 0,
element: SEQUENCE maxLength: NAT OF Contour
];
Span: TYPE ~ RECORD [y, x0, x1: INTEGER];
SpanSequence: TYPE ~ REF SpanSequenceRep;
SpanSequenceRep:
TYPE ~
RECORD [
length: NAT ← 0,
element: SEQUENCE maxLength: NAT OF Span
];
Operations
Scale:
PROC [contour: Contour, scale:
REAL]
RETURNS [Contour];
Return the input contour scaled by the given amount.
Offset:
PROC [contour: Contour, offset: Pair]
RETURNS [Contour];
Return the input contour offset by the given amount.
Center:
PROC [contour: Contour]
RETURNS [Contour];
Return the input contour centered about [0, 0].
Orient:
PROC [contour: Contour]
RETURNS [Contour];
Return the input contour after orienting it to start at the lowest point in y.
Smooth:
PROC [contour: Contour]
RETURNS [Contour];
Replace contour points with weighted local average.
Thin:
PROC [contour: Contour, epsilon:
REAL ← 3.0]
RETURNS [Contour];
Remove redundant points (epsilon is the permissable angular degree deviation from straight).
Normals and Percents
Normals:
PROC [contour: Contour]
RETURNS [PairSequence];
Return the set of two-dimensional normals for the contour.
Percents:
PROC [contour: Contour]
RETURNS [RealSequence];
Set the percentages of each point according to its distance along the contour.
AtPercent:
PROC [contour: Contour, percent:
REAL]
RETURNS [RealIndex];
Return the index into contour.pairs which is percent percentage around the contour.
PercentPair:
PROC [contour: Contour, percent:
REAL]
RETURNS [Pair];
Return the contour point at percent percentage around the contour.
PercentNormal:
PROC [contour: Contour, percent:
REAL]
RETURNS [Pair];
Return the (unitized) contour normal at percent percentage around the contour.
Interpolation/ReSampling/Comparing
Interpolate:
PROC [contour0, contour1: Contour, alpha:
REAL]
RETURNS [Contour];
Return the contour that is alpha*contour0+(1.0-alpha)*contour1.
Sample:
PROC [contour: Contour, nPairs:
INTEGER]
RETURNS [Contour];
Return a sampled copy of contour.
Similar:
PROC [contour0, contour1: Contour]
RETURNS [
REAL];
Return a measure of the similarity between the two contours: 0 => dissimilar, 1 => similar.
Filling/Outlining
Fill:
PROC [context: Context, contour: Contour, color: Color ← Imager.black];
Fill the contour with the current Imager color.
Outline:
PROC [context: Context, contour: Contour, color: Color ← Imager.black];
Outline the contour with the current Imager color.
OutlinePm:
PROC [pm: PixelMap, contour: Contour, color:
CARDINAL ← 0];
Outline the contour with the given color.
FillPm:
PROC [pm: PixelMap, contour: Contour, color:
CARDINAL];
Fill the contour with the given color.