-- CurveDefs.mesa
-- Communications Defs file for Spline Fitting program
-- Maureen Stone 13-Jan-82 16:05:09

DIRECTORY
	Rope USING [ROPE],
	Vector USING [Vec],
	Cubic USING [Bezier];
CurveDefs: CEDAR DEFINITIONS =
BEGIN

SampleHandle: TYPE = REF Sample;
SListHandle: TYPE = REF SList;
ContourHandle: TYPE = REF Contour;
LinkHandle: TYPE = REF Link;
TrajHandle: TYPE = REF Traj;

SV: TYPE = RECORD[s: REAL, v: REAL];
ValueSeq: TYPE = RECORD [s: SEQUENCE l:NAT OF SV];
Values: TYPE = REF ValueSeq;

Sample: TYPE = RECORD
	[next: SampleHandle ← NIL,
	prev: SampleHandle ← NIL,
	xy: Vector.Vec ← [0,0],
	s: REAL ← 0,
	value: REAL
	];
-- sample is a data point.  xy is the [x,y] position of the point 
-- s is arc length, and may be relative to start in an SList
-- values are interesting values computed at each sample.
SList: TYPE = RECORD
	[next: SListHandle ← NIL,
	prev: SListHandle ← NIL,
	nsamples: INTEGER ← 0,
	arcLen: REAL ← 0,
	samples: SampleHandle ← NIL,
	lastSample: SampleHandle ← NIL,
	closed: BOOLEAN ← FALSE
	];
-- SList is a list of Samples.
Contour: TYPE = RECORD
	[next: ContourHandle ← NIL,
	prev: ContourHandle ← NIL,
	sLists: SListHandle ← NIL,
	lastSList: SListHandle ← NIL
	];
-- Contour is a list of SLists which form a closed trajectory.
Link: TYPE = RECORD
	[next: LinkHandle ← NIL,
	prev: LinkHandle ← NIL,
	cubic: Cubic.Bezier
	];
-- a link is either a cubic or a straight line.  Lines will have b1=b2=b3

Traj: TYPE = RECORD
	[next: TrajHandle ← NIL,
	prev: TrajHandle ← NIL,
	links: LinkHandle ← NIL,
	lastLink: LinkHandle ← NIL
	];
-- a Traj (trajectory) is a sequence of links which may form a closed contour


--From FitCubics
FitSpline: PUBLIC PROCEDURE[samples: SampleHandle, npieces: INTEGER ← 1000] RETURNS[LinkHandle];
DrawLink: PUBLIC PROC [link: LinkHandle];

--From Analyze	
AnalyzeContour: PROCEDURE[points: ContourHandle]; 

-- From CurveFitIO
OpenFile: PROC [file: Rope.ROPE];
CloseFile: PROC;
WriteSamples: PROC[samples: SampleHandle];
WriteContour: PROC[contour: ContourHandle, s: REAL, t: Vector.Vec];
WriteTraj: PROCEDURE[t: TrajHandle, first: BOOLEAN ← FALSE];

ContourMain: PROGRAM;
Analyze: PROGRAM;
FitCubics: PROGRAM;
CurveFitIO: PROGRAM;
END.