aboutsummaryrefslogtreecommitdiff
path: root/src/algebra/iviews.as.pamphlet
blob: 37a09af4c2a48d73083c824b4644ae915c188cf5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
\documentclass{article}
\usepackage{axiom}
\begin{document}
\title{\$SPAD/src/algebra iviews.as}
\author{The Axiom Team}
\maketitle
\begin{abstract}
\end{abstract}
\eject
\tableofcontents
\eject
\section{InventorDataSink}
<<InventorDataSink>>=
#include "axiom"
#assert Real

NNI 	==> NonNegativeInteger;
SI 	==> SingleInteger;
DF 	==> DoubleFloat;
POINT 	==> Point DF;
SPACE3  ==> ThreeSpace DoubleFloat;

DefaultSize ==> 65530;

Value ==> Symbol;

InventorDataSink: with {
	CoercibleTo OutputForm;
	new:      () -> %;
	dispose!: % -> ();

	put!:     (%, SI) -> ();
	put!:     (%, DF) -> ();
	put!: (%, String) -> ();

	vstart!: (%, 'int,float', SI) -> ();
	vput!:  (%, SI) -> ();
	vput!:  (%, DF) -> ();

	lstart!:   % -> ();
	lend!:     % -> ();
	export from 'int,float'
} == add {
#if Real
	-- No rep (we cheat!)
	import from SI;
	valOf(x) ==> x pretend Value;
	default sink: %;
	import {
		LISP_:_:GR_-GET_-MEM_-AREA: SI -> %;
		LISP_:_:GR_-KILL_-MEM_-AREA: % -> ();
		LISP_:_:GR_-PUT_-ITEM:	    (%, Value) -> ();
		LISP_:_:GR_-PUT_-LSTART:	     % -> ();
		LISP_:_:GR_-PUT_-LEND:	             % -> ();
		LISP_:_:GR_-INIT_-VECTOR: (%, Value, Value) -> %;
		LISP_:_:GR_-ADD_-TO_-VECTOR:     (%, Value) -> %;
	} from Foreign Lisp;

	new(): % == LISP_:_:GR_-GET_-MEM_-AREA(DefaultSize);
	dispose!(sink): () == LISP_:_:GR_-KILL_-MEM_-AREA(sink);

	put!(sink, si: SI): ()     == LISP_:_:GR_-PUT_-ITEM(sink, valOf(si));
	put!(sink, st: String): () == LISP_:_:GR_-PUT_-ITEM(sink, valOf(st));
	put!(sink, fl: DF): ()     == LISP_:_:GR_-PUT_-ITEM(sink, valOf(fl));

	vstart!(sink, type: 'int,float', sz: SI): () == {
		local sym: Symbol;
		if type = int then 
			sym := coerce("integer");
		else 
			sym := coerce("float");
		LISP_:_:GR_-INIT_-VECTOR(sink, valOf(sym), valOf(sz));
	}

	vput!(sink, si: SI): () == 
		LISP_:_:GR_-ADD_-TO_-VECTOR(sink, valOf(si));
	vput!(sink, df: DF): () == 
		LISP_:_:GR_-ADD_-TO_-VECTOR(sink, valOf(df));

	lstart!(sink): () == LISP_:_:GR_-PUT_-LSTART sink;
	lend!(sink): () == LISP_:_:GR_-PUT_-LEND sink;

	coerce(sink): OutputForm == {
		[outputForm "aSink"]
	}
#else
	Rep ==> Record(count: NonNegativeInteger);
	import from Rep, NNI;
	default sink: %;
	coerce(sink): OutputForm == {
		import from List OutputForm;
		bracket [outputForm "Sink: ", 
			 outputForm coerce rep(sink).count];
	}

	local addn!(sink, n: NNI): () == 
		rep(sink).count := rep(sink).count + n;
	new(): % == per [0];
	dispose!(sink): () == dispose! rep sink;
	
	put!(sink, n: SI): () == addn!(sink, 1 + 4);
	put!(sink, f: DF): () == addn!(sink, 1 + 4);
	put!(sink, s: String): () == {
		addn!(sink, #s + 1 + 1);
	}
	
	vstart!(sink, type: 'int, float', n: SI): () == {
		addn!(sink, 1 + n::NNI*4);
	}

	vput!(sink, n: SI): () == {};
	vput!(sink, n: DF): () == {};

	lstart!(sink): () == addn!(sink, 1);
	lend!(sink): () == addn!(sink, 1);

#endif
}

@
\section{InventorViewPort}
<<InventorViewPort>>=
InventorViewPort: with {
	new:      () -> %;
	new: ThreeSpace DoubleFloat -> %;
	addData!: (%, InventorDataSink) -> %;
	addData!: (%, ThreeSpace DoubleFloat) -> %;
} == add {
#if Real
	import {
		LISP_:_:GR_-MAKE_-VIEW: (SI) -> %;
		LISP_:_:GR_-SET_-DATA:  (%, InventorDataSink) -> ();
	} from Foreign Lisp;
	import from SingleInteger;

	new(): % == LISP_:_:GR_-MAKE_-VIEW(0);

	new(space: ThreeSpace DoubleFloat): % == {
		import from InventorDataSink;
		import from InventorRenderPackage;
		view: % := new();
		addData!(view, space);
		view
	}

	addData!(view: %, data: InventorDataSink): % == {
		LISP_:_:GR_-SET_-DATA(view, data);
		view;
	}

	addData!(view: %, space: ThreeSpace DoubleFloat): % == {
		import from InventorRenderPackage;
		sink: InventorDataSink := new();
		render(sink, space, cartesian$CoordinateSystems(DoubleFloat));
		addData!(view, sink);
		view
	}

#else
	Rep ==> SingleInteger;
	import from Rep;
	new(): % == per 1;
	new(x: ThreeSpace DoubleFloat): % == per 2;
	addData!(view: %, data: InventorDataSink): % == view;
#endif
	
}

@
\section{InventorRenderPackage}
<<InventorRenderPackage>>=
InventorRenderPackage: with {
	render: (InventorDataSink, ThreeSpace DoubleFloat, POINT->POINT) -> ();
} == add {
	default sink: InventorDataSink;
	default space: ThreeSpace DoubleFloat;
	default transform: POINT->POINT;
	import from SI;

	local put!(sink, dims: UniversalSegment SI, 
		   lp: List Point DoubleFloat,
		   f: Point DoubleFloat -> Point DoubleFloat): () == {
		import from NNI, Integer;
		i : SI := 0;
		for x in dims repeat i:= i+1;
		vstart!(sink, float, i*(coerce #lp));
		for p in lp repeat {
			p1 := f(p);
			for idx in dims repeat 
				vput!(sink, p1.(idx::Integer));
		}
	}

	local put!(sink, lp: List SI): () == {
		import from NNI;
		vstart!(sink, int, coerce #lp);
		for p in lp repeat {
			vput!(sink, p);
		}
	}

	local putPoints!(sink, transform, 
			 lpts: List POINT, indexList: List NNI): () == {
		import from Integer;
		if not sorted? indexList 
		then {
			-- not nice!
			lst: List POINT := [];
			for idx in indexList repeat 
				lst := cons(lpts.(coerce idx), lst);
			lpts := reverse! lst;
		}
		put!(sink, 1..3, lpts, transform);
      		if (# first lpts) = 4 
		then {
			put!(sink, "Colours");
			put!(sink, 4..4, lpts, transform);
		}
	}
	render(sink, space, transform): () == {
	 	default ss: SPACE3;
	      	default i: NNI;
		import from List POINT;
		import from List List List NNI;
		import from List List NNI;
		import from List SPACE3;
		import from SingleInteger;
		put!(sink, "ThreeDScene");
      		-- Get the point data
	      	check(space);
      		indices := lllip(space);
      		lpts := lp(space);
      		indexList := concat concat indices;
		put!(sink, "Points");
		putPoints!(sink, transform, lpts, indexList);
      		offset : SI := 0;
		lstart!(sink);
		for ss in components(space) for index in indices repeat {
			closedCurve? ss => {
				put!(sink, "closedCurve");
				n: SI := coerce #(first index);
				put!(sink, offset);
				put!(sink, n);
				offset := offset + n;
			}
			curve? ss=> {
				put!(sink, "curve");
				n: SI := coerce #(first index);
				put!(sink, offset);
				put!(sink, n);
				offset := offset + n;
			}
			polygon? ss => {
				local vertices: SI;
				put!(sink, "polygon");
				vertices := coerce(#(first index)
						   + #(first rest index));
				put!(sink, offset);
				put!(sink, vertices);
				offset := offset+vertices;
			}
			mesh? ss=> {
				local xStep, yStep: SI;
				put!(sink, "mesh");
				xStep := coerce #index;
          			yStep := coerce #(first index);
				put!(sink, offset);
				put!(sink, xStep);
				put!(sink, yStep);
				offset := offset+xStep*yStep;
			}
			point? ss => {
				put!(sink, "points");
				put!(sink, offset);
				put!(sink, 1);
				offset := offset+1;
			}
			error "Unrecognised SubSpace component";
		}
		lend!(sink);
	}
	
}

@
\section{License}
<<license>>=
--Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
--All rights reserved.
--
--Redistribution and use in source and binary forms, with or without
--modification, are permitted provided that the following conditions are
--met:
--
--    - Redistributions of source code must retain the above copyright
--      notice, this list of conditions and the following disclaimer.
--
--    - Redistributions in binary form must reproduce the above copyright
--      notice, this list of conditions and the following disclaimer in
--      the documentation and/or other materials provided with the
--      distribution.
--
--    - Neither the name of The Numerical ALgorithms Group Ltd. nor the
--      names of its contributors may be used to endorse or promote products
--      derived from this software without specific prior written permission.
--
--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
--IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
--TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
--PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
--OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
--EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
--PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
--PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
--LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
--NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
--SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@
<<*>>=
<<license>>

<<InventorDataSink>>
<<InventorViewPort>>
<<InventorRenderPackage>>
@
\eject
\begin{thebibliography}{99}
\bibitem{1} nothing
\end{thebibliography}
\end{document}