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 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
|
/* xsiview3 - XLISP interface to IVIEW dynamic graphics package. */
/* XLISP-STAT 2.1 Copyright (c) 1990, by Luke Tierney */
/* Additions to Xlisp 2.1, Copyright (c) 1989 by David Michael Betz */
/* You may give out copies of this software; for conditions see the */
/* file COPYING included with this distribution. */
#include "xlisp.h"
#include "xlstat.h"
/* external variables */
extern LVAL s_invisible, s_normal, s_hilited, s_selected;
extern LVAL s_solid, s_dashed;
extern LVAL sk_point_labels;
extern LVAL s_left, s_center, s_right, s_top, s_bottom;
extern LVAL sk_draw, sk_redraw, sk_redraw_content,sk_scale, sk_basis;
/* static global variables */
static int maxvars = 0;
static double **transform, *transformdata;
static int *inbasis;
static IVIEW_WINDOW wind;
static int range_type;
/**************************************************************************/
/** **/
/** General IView Data Functions **/
/** **/
/**************************************************************************/
static LVAL base_variable_label(V)
{
int var, set = FALSE;
char *label = NULL;
LVAL result;
var = getfixnum(xlgafixnum());
if (moreargs()) {
set = TRUE;
label = (char *) getstring(xlgastring());
}
xllastarg();
if (set) IViewSetVariableLabel(wind, var, label);
label = IViewVariableLabel(wind, var);
if (label == NULL) result = cvstring("");
else result = cvstring(label);
return(result);
}
static LVAL variable_label(V)
{
return(recursive_subr_map_elements(base_variable_label, variable_label));
}
LVAL iview_variable_label(V)
{
wind = (IVIEW_WINDOW) get_iview_address(xlgaobject());
return(variable_label());
}
static LVAL base_range(V)
{
int var, set = FALSE;
double low, high;
var = getfixnum(xlgafixnum());
if (moreargs()) {
set = TRUE;
low = makefloat(xlgetarg());
high = makefloat(xlgetarg());
}
if (set) {
if (range_type != 'S') IViewSetRange(wind, var, low, high);
else IViewSetScaledRange(wind, var, low, high);
}
if (range_type != 'S') IViewGetRange(wind, var, &low, &high);
else IViewGetScaledRange(wind, var, &low, &high);
return(double_list_2(low, high));
}
static LVAL range(V)
{
return(recursive_subr_map_elements(base_range, range));
}
LVAL iview_range(V)
{
LVAL object = xlgaobject(), result, *oldargv = NULL;
int set = (xlargc > 1) ? TRUE : FALSE, draw, oldargc = 0;
wind = (IVIEW_WINDOW) get_iview_address(object);
draw = draw_key_arg(TRUE);
range_type = 'N';
if (set) {
oldargc = xlargc;
oldargv = xlargv;
}
result = range();
if (set) {
xlargc = oldargc - 3;
xlargv = oldargv + 3;
check_redraw(object, draw, FALSE);
}
return(result);
}
LVAL iview_scaled_range(V)
{
LVAL object = xlgaobject(), result, *oldargv = NULL;
int set = (xlargc > 1) ? TRUE : FALSE, draw, oldargc = 0;
wind = (IVIEW_WINDOW) get_iview_address(object);
draw = draw_key_arg(TRUE);
range_type = 'S';
if (set) {
oldargc = xlargc;
oldargv = xlargv;
}
result = range();
if (set) {
xlargc = oldargc - 3;
xlargv = oldargv + 3;
check_redraw(object, draw, FALSE);
}
return(result);
}
static LVAL base_screen_range(V)
{
int var, set = FALSE;
int low, high;
var = getfixnum(xlgafixnum());
if (moreargs()) {
set = TRUE;
low = getfixnum(xlgafixnum());
high = getfixnum(xlgafixnum());
}
xllastarg();
if (set) IViewSetScreenRange(wind, var, low, high);
IViewGetScreenRange(wind, var, &low, &high);
return(integer_list_2(low, high));
}
static LVAL screen_range(V)
{
return(recursive_subr_map_elements(base_screen_range, screen_range));
}
LVAL iview_screen_range(V)
{
wind = (IVIEW_WINDOW) get_iview_address(xlgaobject());
return(screen_range());
}
static VOID set_internal_transformation P3C(int, vars, LVAL, m, LVAL, b)
{
int i, j, k, rows, cols;
LVAL data;
if (vars <= 0) return;
if (vars > maxvars) {
maxvars = 0;
StFree(transformdata);
StFree(transform);
StFree(inbasis);
transformdata = (double *) StCalloc(vars * vars, sizeof(double));
transform = (double **) StCalloc(vars, sizeof(double *));
for (i = 0; i < vars; i++) transform[i] = transformdata + vars * i;
inbasis = (int *) StCalloc(vars, sizeof(double));
maxvars = vars;
}
if (! matrixp(m)) xlerror("not a matrix", m);
rows = numrows(m);
cols = numcols(m);
if (rows > vars) rows = vars;
if (cols > vars) cols = vars;
if (rows != cols) xlerror("bad transformation matrix", m);
/* fill in upper left corner of transform from m; rest is identity */
data = getdarraydata(m);
for (i = 0, k = 0; i < rows; i++) {
for (j = 0; j < cols; j++, k++)
transform[i][j] = makefloat(gettvecelement(data, k));
for (j = cols; j < vars; j++)
transform[i][j] = (i == j) ? 1.0 : 0.0;
}
for (i = rows; i < vars; i++)
for (j = 0; j < vars; j++)
transform[i][j] = (i == j) ? 1.0 : 0.0;
/* figure out basis elements using b and size of m */
if (b != NIL) {
if (! seqp(b)) xlerror("not a sequence", b);
if (seqlen(b) != rows) xlerror("wrong length for basis", b);
for (i = 0; i < rows; i++)
inbasis[i] = (getnextelement(&b, i) != NIL) ? TRUE : FALSE;
}
else for (i = 0; i < rows; i++) inbasis[i] = TRUE;
for (i = rows; i < vars; i++) inbasis[i] = FALSE;
}
static LVAL newmatrix P2C(unsigned, r, unsigned, c)
{
LVAL rows, cols, dim, result;
xlstkcheck(3);
xlsave(rows);
xlsave(cols);
xlsave(dim);
rows = cvfixnum((FIXTYPE) r);
cols = cvfixnum((FIXTYPE) c);
dim = list2(rows, cols);
result = mkarray(dim, NIL, NIL, s_true);
xlpopn(3);
return(result);
}
static LVAL make_transformation P2C(double **, a, int, vars)
{
LVAL result, data;
int i, j, k;
if (a == NULL) return(NIL);
xlsave1(result);
result = newmatrix(vars, vars);
data = getdarraydata(result);
for (i = 0, k = 0; i < vars; i++)
for (j = 0; j < vars; j++, k++)
settvecelement(data, k, cvflonum((FLOTYPE) a[i][j]));
xlpop();
return(result);
}
LVAL iview_transformation(V)
{
IVIEW_WINDOW w;
LVAL m = NULL, object;
int set = FALSE;
int vars;
object = xlgaobject();
w = (IVIEW_WINDOW) get_iview_address(object);
if (moreargs()) {
set = TRUE;
m = xlgetarg();
}
vars = IViewNumVariables(w);
if (set) {
if (m == NIL) IViewSetIdentityTransformation(w);
else {
set_internal_transformation(vars, m, NIL);
IViewSetTransformation(w, transform);
}
check_redraw(object, TRUE, TRUE);
}
else m = (IViewIsTransformed(w))
? make_transformation(IViewTransformation(w), vars) : NIL;
return(m);
}
LVAL iview_apply_transformation(V)
{
IVIEW_WINDOW w;
LVAL m, b, object;
int vars;
object = xlgaobject();
w = (IVIEW_WINDOW) get_iview_address(object);
m = xlgamatrix();
if (! xlgetkeyarg(sk_basis, &b)) b = NIL;
vars = IViewNumVariables(w);
set_internal_transformation(vars, m, b);
IViewApplyTransformation(w, transform, inbasis);
check_redraw(object, TRUE, TRUE);
return(NIL);
}
/**************************************************************************/
/** **/
/** IView Data Drawing Functions **/
/** **/
/**************************************************************************/
static LVAL draw_data P1C(int, which)
{
IVIEW_WINDOW w;
int var1, var2, m, n;
w = (IVIEW_WINDOW) get_iview_address(xlgaobject());
var1 = getfixnum(xlgafixnum());
var2 = getfixnum(xlgafixnum());
m = getfixnum(xlgafixnum());
n = getfixnum(xlgafixnum());
xllastarg();
switch(which) {
case 'P': IViewDrawDataPoints(w, var1, var2, m, n); break;
case 'L': IViewDrawDataLines(w, var1, var2, m, n); break;
#ifdef USESTRINGS
case 'S': IViewDrawDataStrings(w, var1, var2, m, n); break;
#endif /* USESTRINGS */
}
return(NIL);
}
LVAL iview_draw_data_points(V) { return(draw_data('P')); }
LVAL iview_draw_data_lines(V) { return(draw_data('L')); }
#ifdef USESTRINGS
LVAL iview_draw_data_strings(V) { return(draw_data('S')); }
#endif /* USESTRINGS */
/**************************************************************************/
/** **/
/** Standard Callback Functions **/
/** **/
/**************************************************************************/
LVAL iview_std_mark_points_in_rect(V)
{
IVIEW_WINDOW w;
int left, top, width, height;
w = (IVIEW_WINDOW) get_iview_address(xlgaobject());
left = getfixnum(xlgafixnum());
top = getfixnum(xlgafixnum());
width = getfixnum(xlgafixnum());
height = getfixnum(xlgafixnum());
xllastarg();
IViewStdMarkPointsInRect(w, left, top, width, height);
return(NIL);
}
LVAL iview_std_adjust_screen(V)
{
IVIEW_WINDOW w;
w = (IVIEW_WINDOW) get_iview_address(xlgaobject());
IViewStdAdjustScreen(w);
return(NIL);
}
PointState decode_point_state P1C(LVAL, state)
{
if (state == s_invisible) return(pointInvisible);
else if (state == s_normal) return(pointNormal);
else if (state == s_hilited) return(pointHilited);
else if (state == s_selected) return(pointSelected);
else xlerror("unknown point state", state);
return pointNormal; /* not reached */
}
LVAL iview_std_adjust_points_in_rect(V)
{
IVIEW_WINDOW w;
int left, top, width, height;
PointState state;
w = (IVIEW_WINDOW) get_iview_address(xlgaobject());
left = getfixnum(xlgafixnum());
top = getfixnum(xlgafixnum());
width = getfixnum(xlgafixnum());
height = getfixnum(xlgafixnum());
state = decode_point_state(xlgetarg());
xllastarg();
IViewStdAdjustPointsInRect(w, left, top, width, height, state);
return(NIL);
}
LVAL iview_std_adjust_screen_point(V)
{
LVAL object;
int point;
object = xlgaobject();
point = getfixnum(xlgafixnum());
xllastarg();
IViewStdAdjustScreenPoint((IVIEW_WINDOW) get_iview_address(object), point);
return(NIL);
}
/**************************************************************************/
/** **/
/** IView Rotation Functions **/
/** **/
/**************************************************************************/
LVAL iview_rotate_2(V)
{
IVIEW_WINDOW w;
int var1, var2;
double alpha;
LVAL object;
object = xlgaobject();
w = (IVIEW_WINDOW) get_iview_address(object);
var1 = getfixnum(xlgafixnum());
var2 = getfixnum(xlgafixnum());
alpha = makefloat(xlgetarg());
IViewRotate2(w, var1, var2, alpha);
check_redraw(object, TRUE, TRUE);
return(NIL);
}
/**************************************************************************/
/** **/
/** Miscellaneous Functions **/
/** **/
/**************************************************************************/
LVAL iview_get_nice_range(V)
{
double low, high;
int ticks;
LVAL temp, result;
low = makefloat(xlgetarg());
high = makefloat(xlgetarg());
ticks = getfixnum(xlgafixnum());
xllastarg();
GetNiceRange(&low, &high, &ticks);
xlstkcheck(2);
xlsave(result);
xlsave(temp);
temp = cvfixnum((FIXTYPE) ticks); result = consa(temp);
temp = cvflonum((FLOTYPE) high); result = cons(temp, result);
temp = cvflonum((FLOTYPE) low); result = cons(temp, result);
xlpopn(2);
return(result);
}
LVAL iview_adjust_depth_cuing(V)
{
LVAL object;
int vz;
IVIEW_WINDOW w;
int i, low, high, cut1, cut2, cut3, z, nz;
int next, n;
object = xlgaobject();
vz = getfixnum(xlgafixnum());
xllastarg();
w = (IVIEW_WINDOW) GETIVIEWADDRESS(object);
if (IVIEW_WINDOW_NULL(w)) return(NIL);
IViewGetScreenRange(w, vz, &low, &high);
cut1 = (low + high) / 2 - (high - low) / 8;
cut2 = (low + high) / 2;
cut3 = (low + high) / 2 + (high - low) / 8;
n = IViewNumPoints(w);
IViewDepthCuePoints(w, vz, cut1, cut2, cut3, 0, n);
cut1 = (low + high) / 2 - (high - low) / 8;
cut3 = (low + high) / 2 + (high - low) / 8;
n = IViewNumLines(w);
for (i = 0; i < n; i++) {
z = IViewLineScreenValue(w, vz, i);
next = IViewNextLine(w, i);
nz = (next >= 0)
? IViewLineScreenValue(w, vz, next) : z;
z = (z + nz) / 2;
if (z < cut1) IViewSetLineWidth(w, i, 1);
else if (z < cut3) IViewSetLineWidth(w, i, 2);
else IViewSetLineWidth(w, i, 3);
}
return(NIL);
}
|