G2dContour.mesa
Copyright Ó 1985, 1988, 1992 by Xerox Corporation. All rights reserved.
Bloomenthal, July 1, 1992 7:04 pm PDT
Glassner, March 18, 1990 3:28:34 pm PST
DIRECTORY G2dBasic, G2dVector, Imager, ImagerSample, IO, Rope, ViewerClasses;
G2dContour: CEDAR DEFINITIONS
IMPORTS Imager
~ BEGIN
Error:      ERROR [code: ATOM, reason: ROPE];
Note
The contour type supported by this interface is, simply, a sequence of two-dimensional points; there is no higher or analytic representation for the contour. The contour may be closed, in which case the last point of the sequence connects to the first point.
Local Types
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
clientData:      REF ¬ NIL   
];
ContourSequence:  TYPE ~ REF ContourSequenceRep;
ContourSequenceRep:  TYPE ~ RECORD [
length:       CARDINAL ¬ 0,
element:       SEQUENCE maxLength: CARDINAL OF Contour
];
Span:      TYPE ~ RECORD [y, x0, x1: INTEGER];
SpanSequence:   TYPE ~ REF SpanSequenceRep;
SpanSequenceRep:  TYPE ~ RECORD [
length:       CARDINAL ¬ 0,
element:       SEQUENCE maxLength: CARDINAL OF Span
];
RealIndex:    TYPE ~ RECORD [n: NAT ¬ 0, alpha: REAL ¬ 0.0];
Imported Types
ROPE:      TYPE ~ Rope.ROPE;
STREAM:     TYPE ~ IO.STREAM;
Viewer:     TYPE ~ ViewerClasses.Viewer;
Context:      TYPE ~ Imager.Context;
SampleMap:    TYPE ~ ImagerSample.SampleMap;
Rectangle:    TYPE ~ Imager.Rectangle;
Color:      TYPE ~ Imager.Color;
Border:     TYPE ~ G2dBasic.Border;
Pair:      TYPE ~ G2dBasic.Pair;      -- RECORD [x, y: REAL]
PairSequence:   TYPE ~ G2dBasic.PairSequence;
PairSequenceRep:  TYPE ~ G2dBasic.PairSequenceRep;
IntegerPair:    TYPE ~ G2dBasic.IntegerPair;    -- RECORD [x, y: INTEGER]
IntegerPairSequence: TYPE ~ G2dBasic.IntegerPairSequence;
IntegerPairSequenceRep: TYPE ~ G2dBasic.IntegerPairSequenceRep;
NatPair:     TYPE ~ G2dBasic.NatPair;     -- RECORD [x, y: Nat]
NatPairSequence:  TYPE ~ G2dBasic.NatPairSequence;
NatPairSequenceRep: TYPE ~ G2dBasic.NatPairSequenceRep;
RealSequence:   TYPE ~ G2dBasic.RealSequence;
RealSequenceRep:  TYPE ~ G2dBasic.RealSequenceRep;
Contour Creation
FromPairs: PROC [pairs: PairSequence, closed: BOOL ¬ FALSE, t: REAL ¬ 0.0]
RETURNS [Contour];
Return the contour given the input sequence.
FromIntegerPairs: PROC [
integerPairs: IntegerPairSequence, closed: BOOL ¬ FALSE, t: REAL ¬ 0.0]
RETURNS [Contour];
Return the contour given the input sequence.
General Operations
IntegerPairsFromPairs: PROC [pairs: PairSequence] RETURNS [IntegerPairSequence];
Convert the sequence.
PairsFromIntegerPairs: PROC [integerPairs: IntegerPairSequence] RETURNS [PairSequence];
Convert the sequence.
ShiftPairs: PROC [pairs: PairSequence, shift: INTEGER];
Barrel shift of the sequence; positive shift is to the left, negative to the right.
Scale: PROC [contour: Contour, scale: Pair] 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.
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.
Smoothing and Thinning
SmoothPairs: PROC [src: PairSequence, dst: PairSequence ¬ NIL] RETURNS [PairSequence];
Compute weighted local average of src; use dst if # NIL and long enough.
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 permissible angular degree deviation from straight).
Interpolation/Resampling/Comparing
ResampleNats: PROC [src: NatPairSequence, dstnum: NAT, dst: PairSequence ¬ NIL]
RETURNS [PairSequence];
Resample src curve to have dstnum (approx) equally spaced points; nats in, reals out.
Avoids new allocation if dst # NIL and is long enough.
ResamplePairs: PROC [src: PairSequence, dstnum: NAT, dst: PairSequence ¬ NIL]
RETURNS [PairSequence];
Resample src curve to have dstnum (approx) equally spaced points; reals in, reals out.
Avoids new allocation if dst # NIL and is long enough.
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 g2dContour: 0 => dissimilar, 1 => similar.
Inside/Outside Test
InsideContour: PROC [p: Pair, pairs: PairSequence] RETURNS [Border];
Determine whether p is within the closed boundary defined by pairs.
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
Normals: PROC [contour: Contour] RETURNS [PairSequence];
Return the set of two-dimensional normals for the contour.
Percents
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.
Spans
Spans: PROC [contour: Contour, rectangle: Rectangle] RETURNS [SpanSequence];
Create a sequence of scanline segments which constitue the pixelated contour region.
FillSpans: PROC [map: SampleMap, 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.
OutlineMap: PROC [map: SampleMap, contour: Contour, color: CARDINAL ¬ 0];
Outline the contour with the given color.
FillMap: PROC [map: SampleMap, 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: BOOL ¬ FALSE];
Paint the given contour.
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.