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;
Contours: CEDAR DEFINITIONS
IMPORTS Imager
~ BEGIN
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:       BOOLFALSE,    -- if true, last point connects to 1st
circle:        BOOLTRUE,    -- 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
];
Attributes
ContourOK: PUBLIC PROC [contour: Contour] RETURNS [BOOL];
Return true if contour and contour.pairs are non-nil.
MinMax: PROC [contour: Contour] RETURNS [min, max: Pair];
Return the minimum and maximum of the contour.
Centroid: PROC [contour: Contour] RETURNS [Pair];
Return the center of the contour.
Area: PROC [contour: Contour] RETURNS [REAL];
Return contour area: + if clockwise, - if counterclockwise, 0 if not closed.
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).
Circles
CirclePairs: PROC [nPairs: INTEGER] RETURNS [PairSequence];
Return the points of a circle.
Circle: PROC [nPairs: INTEGER] RETURNS [Contour];
Return a circular contour of nPairs number of points.
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.
Spans
Spans: PROC [contour: Contour, rectangle: Rectangle] RETURNS [SpanSequence];
Create a sequence of scanline segments which constitue the pixelated contour region.
FillSpans: PROC [pm: PixelMap, spans: SpanSequence, color: CARDINAL];
Color the spans.
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.
Copying
Copy: PROC [contour: Contour] RETURNS [Contour];
Return a copy of the input contour; the contour points and normals are copied.
CopySequence: PROC [contour: ContourSequence] RETURNS [ContourSequence];
Return a copy of the input sequence.
Painting
Paint: PUBLIC PROC [contour: Contour, context: Context, paintNormals: BOOLFALSE];
Paint the given contour.
To/From Controls
FromControl: PROC [control: Control, t: REAL ← 0.0] RETURNS [Contour];
Return the contour from control, normalized by viewer dimensions.
ToControl: PROC [control: Control, contour: Contour, repaint: BOOLTRUE];
Set the control with the given contour, scaled by its viewer dimensions.
IO
Write: PROC [stream: STREAM, contour: Contour];
Write the given contour to the given stream.
Read: PROC [stream: STREAM] RETURNS [Contour];
Read the given contour from the given stream.
END.