|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T t
Length: 17601 (0x44c1)
Types: TextFile
Names: »testc.c«
└─⟦db229ac7e⟧ Bits:30007240 EUUGD20: SSBA 1.2 / AFW Benchmarks
└─⟦this⟧ »EUUGD20/AFUU-ssba1.21/ssba1.21E/testc/testc.c«
└─⟦this⟧ »EUUGD20/AFUU-ssba1.21/ssba1.21F/testc/testc.c«
#include <stdio.h>
#include "testc1.h"
#include "testc2.h"
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
/*
* define the minimum intensity visible on the monitor; this is
* monitor specific and should range between 0 and 1
*/
#define MIN_INTENSITY 0.05
gtcell(inPtr)
ArteG_C_Test *inPtr;
{
Gfile *fp;
Gint wkstid;
register Gint i; /* general local variable */
Glimit window; /* window for NT */
Glimit viewport; /* viewport for NT */
Glimit wsWindow; /* workstation window */
Glimit wsViewport; /* workstation viewport */
Gpoint pos[5]; /* polyline coordinates */
Grect rectangle; /* cell rectangle points */
/* dimensions of color index array */
static Gidim dimColorInd = {4, 4};
static Gint colorIndex[16] = {
1, 0, 0, 2,
0, 3, 4, 0,
0, 5, 6, 0,
7, 0, 0, 8}; /* color index array */
Gpoint fixedPt;
Gpoint shiftVec;
Gfloat rotate;
Gscale scale;
Gcsw coordSwitch;
Gfloat inMatrix[2][3];
Gfloat segTran[13][2][3]; /* seg transform matrices */
Gint segName; /* segment name */
Gpoint textPos; /* text position for labels */
Gtxfp txfp; /* text font and precision */
Gchar label[13][20]; /* label strings */
/**
** for ray traced image
**/
static Grect rayRectangle = {60.0, 640.0, 900.0, 0.0};
static Gidim dimensions = {420, 320};
static Gint colors[] = {
#include "testc3.h"
};
Gint index;
Gint numColors;
Gint rayColorIndex;
Gcobundl rgb; /* r, g, b */
double color;
double dtmp1, dtmp2, dtmp3;
Gwsclass class; /* workstation classification */
Gchar response[10]; /* response to ray traced question */
Gdspsize display;
Gwstables wstables;
Gcofac cofac;
Gcobundl cobundl;
Gint error;
Gint bufsize, fac_size;
int err;
fp = inPtr->fp;
wkstid = inPtr->wkstid;
fprintf(fp, " gtcell\n\n\n");
/* set NT's */
window.xmin = 0.0;
window.xmax = 200.0;
window.ymin = 0.0;
window.ymax = 200.0;
for (i = 1; i <= 13; i++) {
if (inPtr->err_ctr < (err = gsetwindow(i, &window)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gsetwindow\n");
}
}
i = 1;
for (viewport.ymin = 0.75, viewport.ymax = 1.0; viewport.ymax >= 0.5; viewport.ymin -= 0.25, viewport.ymax -= 0.25) {
for (viewport.xmin = 0.0, viewport.xmax = 0.25; viewport.xmin < 1.0; viewport.xmin += 0.25, viewport.xmax += 0.25) {
if (i == 2) {
/* special case - viewport is not square */
viewport.xmin += 0.075;
viewport.xmax -= 0.075;
}
if (inPtr->err_ctr < (err = gsetviewport(i, &viewport)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gsetviewport\n");
}
if (i == 2) {
/* set it back */
viewport.xmin -= 0.075;
viewport.xmax += 0.075;
}
/* draw border at Viewport bounds */
if (inPtr->err_ctr < (err = gselntran(i)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gselntran\n");
}
pos[0].x = window.xmin; pos[0].y = window.ymin;
pos[1].x = window.xmin; pos[1].y = window.ymax;
pos[2].x = window.xmax; pos[2].y = window.ymax;
pos[3].x = window.xmax; pos[3].y = window.ymin;
pos[4].x = window.xmin; pos[4].y = window.ymin;
if (inPtr->err_ctr < (err = gpolyline(5, pos)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gpolyline\n");
}
i++;
}
}
/* one more! */
viewport.xmin = 0.0;
viewport.xmax = 0.25;
viewport.ymin = 0.0;
viewport.ymax = 0.25;
if (inPtr->err_ctr < (err = gsetviewport(i, &viewport)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gsetviewport\n");
}
/* draw border at Viewport bounds */
if (inPtr->err_ctr < (err = gselntran(i)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gselntran\n");
}
pos[0].x = window.xmin; pos[0].y = window.ymin;
pos[1].x = window.xmin; pos[1].y = window.ymax;
pos[2].x = window.xmax; pos[2].y = window.ymax;
pos[3].x = window.xmax; pos[3].y = window.ymin;
pos[4].x = window.xmin; pos[4].y = window.ymin;
if (inPtr->err_ctr < (err = gpolyline(5, pos)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gpolyline\n");
}
/* set character attributes for text labels */
if (inPtr->err_ctr < (err = gsetcharheight(10.0)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gsetcharheight\n");
}
txfp.font = 5;
txfp.prec = GP_STROKE;
if (inPtr->err_ctr < (err = gsettextfontprec(&txfp)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gsettextfontprec\n");
}
/* set up label strings */
(void)strcpy(label[0], "Cell Array");
(void)strcpy(label[1], "NT");
(void)strcpy(label[2], "Segment Translate");
(void)strcpy(label[3], "Segment Scale");
(void)strcpy(label[4], "Rotate PI/4");
(void)strcpy(label[5], "Rotate PI/2");
(void)strcpy(label[6], "Rotate 3PI/4");
(void)strcpy(label[7], "Rotate PI");
(void)strcpy(label[8], "Rotate 5PI/4");
(void)strcpy(label[9], "Rotate 3PI/2");
(void)strcpy(label[10], "Rotate 7PI/4");
(void)strcpy(label[11], "Rotate 2PI");
(void)strcpy(label[12], "Skew");
/* set up segment transformations */
fixedPt.x = 100.0; fixedPt.y = 100.0;
shiftVec.x = 0.0; shiftVec.y = 0.0;
rotate = 0;
scale.x_scale = 1.0; scale.y_scale = 1.0;
coordSwitch = GWC;
if (inPtr->err_ctr < (err = gselntran(1)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gselntran\n");
}
if (inPtr->err_ctr < (err = gevaltran(
&fixedPt, &shiftVec, rotate, &scale, coordSwitch, segTran[0])))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gevaltran\n");
}
fixedPt.x = 100.0; fixedPt.y = 100.0;
shiftVec.x = 0.0; shiftVec.y = 0.0;
rotate = 0;
scale.x_scale = 1.0; scale.y_scale = 1.0;
coordSwitch = GWC;
if (inPtr->err_ctr < (err = gselntran(2)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gselntran\n");
}
if (inPtr->err_ctr < (err = gevaltran(
&fixedPt, &shiftVec, rotate, &scale, coordSwitch, segTran[1])))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gevaltran\n");
}
fixedPt.x = 100.0; fixedPt.y = 100.0;
shiftVec.x = 24.0; shiftVec.y = 32.0;
rotate = 0;
scale.x_scale = 1.0; scale.y_scale = 1.0;
coordSwitch = GWC;
if (inPtr->err_ctr < (err = gselntran(3)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gselntran\n");
}
if (inPtr->err_ctr < (err = gevaltran(
&fixedPt, &shiftVec, rotate, &scale, coordSwitch, segTran[2])))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gevaltran\n");
}
fixedPt.x = 100.0; fixedPt.y = 100.0;
shiftVec.x = 0.0; shiftVec.y = 0.0;
rotate = 0;
scale.x_scale = 1.2; scale.y_scale = 0.7;
coordSwitch = GWC;
if (inPtr->err_ctr < (err = gselntran(4)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gselntran\n");
}
if (inPtr->err_ctr < (err = gevaltran(
&fixedPt, &shiftVec, rotate, &scale, coordSwitch, segTran[3])))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gevaltran\n");
}
fixedPt.x = 100.0; fixedPt.y = 100.0;
shiftVec.x = 0.0; shiftVec.y = 0.0;
rotate = M_PI / 4.0;
scale.x_scale = 1.0; scale.y_scale = 1.0;
coordSwitch = GWC;
if (inPtr->err_ctr < (err = gselntran(5)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gselntran\n");
}
if (inPtr->err_ctr < (err = gevaltran(
&fixedPt, &shiftVec, rotate, &scale, coordSwitch, segTran[4])))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gevaltran\n");
}
fixedPt.x = 100.0; fixedPt.y = 100.0;
shiftVec.x = 0.0; shiftVec.y = 0.0;
rotate = M_PI / 2.0;
scale.x_scale = 1.0; scale.y_scale = 1.0;
coordSwitch = GWC;
if (inPtr->err_ctr < (err = gselntran(6)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gselntran\n");
}
if (inPtr->err_ctr < (err = gevaltran(
&fixedPt, &shiftVec, rotate, &scale, coordSwitch, segTran[5])))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gevaltran\n");
}
fixedPt.x = 100.0; fixedPt.y = 100.0;
shiftVec.x = 0.0; shiftVec.y = 0.0;
rotate = 3.0 * M_PI / 4.0;
scale.x_scale = 1.0; scale.y_scale = 1.0;
coordSwitch = GWC;
if (inPtr->err_ctr < (err = gselntran(7)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gselntran\n");
}
if (inPtr->err_ctr < (err = gevaltran(
&fixedPt, &shiftVec, rotate, &scale, coordSwitch, segTran[6])))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gevaltran\n");
}
fixedPt.x = 100.0; fixedPt.y = 100.0;
shiftVec.x = 0.0; shiftVec.y = 0.0;
rotate = M_PI;
scale.x_scale = 1.0; scale.y_scale = 1.0;
coordSwitch = GWC;
if (inPtr->err_ctr < (err = gselntran(8)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gselntran\n");
}
if (inPtr->err_ctr < (err = gevaltran(
&fixedPt, &shiftVec, rotate, &scale, coordSwitch, segTran[7])))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gevaltran\n");
}
fixedPt.x = 100.0; fixedPt.y = 100.0;
shiftVec.x = 0.0; shiftVec.y = 0.0;
rotate = 5.0 * M_PI / 4.0;
scale.x_scale = 1.0; scale.y_scale = 1.0;
coordSwitch = GWC;
if (inPtr->err_ctr < (err = gselntran(9)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gselntran\n");
}
if (inPtr->err_ctr < (err = gevaltran(
&fixedPt, &shiftVec, rotate, &scale, coordSwitch, segTran[8])))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gevaltran\n");
}
fixedPt.x = 100.0; fixedPt.y = 100.0;
shiftVec.x = 0.0; shiftVec.y = 0.0;
rotate = 3.0 * M_PI / 2.0;
scale.x_scale = 1.0; scale.y_scale = 1.0;
coordSwitch = GWC;
if (inPtr->err_ctr < (err = gselntran(10)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gselntran\n");
}
if (inPtr->err_ctr < (err = gevaltran(
&fixedPt, &shiftVec, rotate, &scale, coordSwitch, segTran[9])))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gevaltran\n");
}
fixedPt.x = 100.0; fixedPt.y = 100.0;
shiftVec.x = 0.0; shiftVec.y = 0.0;
rotate = 7.0 * M_PI / 4.0;
scale.x_scale = 1.0; scale.y_scale = 1.0;
coordSwitch = GWC;
if (inPtr->err_ctr < (err = gselntran(11)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gselntran\n");
}
if (inPtr->err_ctr < (err = gevaltran(
&fixedPt, &shiftVec, rotate, &scale, coordSwitch, segTran[10])))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gevaltran\n");
}
fixedPt.x = 100.0; fixedPt.y = 100.0;
shiftVec.x = 0.0; shiftVec.y = 0.0;
rotate = 2.0 * M_PI;
scale.x_scale = 1.0; scale.y_scale = 1.0;
coordSwitch = GWC;
if (inPtr->err_ctr < (err = gselntran(12)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gselntran\n");
}
if (inPtr->err_ctr < (err = gevaltran(
&fixedPt, &shiftVec, rotate, &scale, coordSwitch, segTran[11])))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gevaltran\n");
}
inMatrix[0][0] = 1.0;
inMatrix[0][1] = 0.5;
inMatrix[0][2] = 0.0;
inMatrix[1][0] = 0.0;
inMatrix[1][1] = 1.0;
inMatrix[1][2] = 0.0;
fixedPt.x = 60.0; fixedPt.y = 60.0;
shiftVec.x = 40.0; shiftVec.y = 40.0;
rotate = 0.0;
scale.x_scale = 1.0; scale.y_scale = 1.0;
coordSwitch = GWC;
if (inPtr->err_ctr < (err = gselntran(13)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gselntran\n");
}
if (inPtr->err_ctr < (err = gaccumtran(inMatrix,
&fixedPt, &shiftVec, rotate, &scale, coordSwitch, segTran[12])))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gaccumtran\n");
}
/* set up rectangle for cell array */
rectangle.ul.x = 40.0;
rectangle.lr.y = 40.0;
rectangle.lr.x = 160.0;
rectangle.ul.y = 160.0;
textPos.x = 10.0; textPos.y = 10.0;
/* draw cell arrays */
for (i = 1; i <= 13; i++) {
if (i == 13) {
rectangle.ul.x = 0.0;
rectangle.lr.y = 0.0;
rectangle.lr.x = 120.0;
rectangle.ul.y = 120.0;
}
if (inPtr->err_ctr < (err = gselntran(i)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gselntran\n");
}
if (inPtr->err_ctr < (err = gcreateseg((long)i)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gcreateseg\n");
}
if (inPtr->err_ctr < (err = gsetsegtran((long)i, segTran[i - 1])))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gsetsegtran\n");
}
if (inPtr->err_ctr < (err = gcellarray(&rectangle,
&dimColorInd, colorIndex)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gcellarray\n");
}
if (inPtr->err_ctr < (err = gcloseseg()))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gcloseseg\n");
}
if (inPtr->err_ctr < (err = gtext(&textPos, label[i - 1])))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gtext\n");
}
}
/*****************************************************************************/
/******* display ray traced picture using cell array - looks best in color ***/
/* ray traced picture only on raster class devices */
ginqwsclass(inPtr->wsType, &class, &error);
if (error != E_NO_ERROR)
return;
if (class != GRASTER)
return;
if (inPtr->pause == 'y')
{
fprintf(fp, "Test cell array capabilities using a ray traced picture?\n");
fprintf(fp, "(This test runs for 2 minutes on a Sun 3.) [y/n] ");
gets(response);
if (response[0] != 'y')
return;
}
bufsize = 0;
ginqcolourfacil(inPtr->wsType, bufsize, &fac_size, &cofac, &error);
if (error != E_NO_ERROR)
fprintf(fp, "Wrong return value from gInqColourFacil\n");
/* message based on mono or color */
if (cofac.coavail == GMONOCHROME)
fprintf(fp, "\nBegin drawing ray traced picture (looks best on color monitor)\n");
else
fprintf(fp, "\nBegin drawing grey-scale ray traced picture\n");
ginqdisplaysize(inPtr->wsType, &display, &error);
if (error != E_NO_ERROR)
fprintf(fp, "Wrong return value from gInqDisplaySize\n");
wsViewport.xmin = 0.0;
wsViewport.ymin = 0.0;
wsViewport.xmax = display.raster.x - 1;
wsViewport.ymax = display.raster.y - 1;
if (inPtr->err_ctr < (err = gsetwsviewport(wkstid, &wsViewport)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gsetwsviewport\n");
}
wsWindow.xmin = 0.0;
wsWindow.ymin = 0.0;
wsWindow.xmax = 1.0;
wsWindow.ymax = wsViewport.ymax / wsViewport.xmax;
if (inPtr->err_ctr < (err = gsetwswindow(wkstid, &wsWindow)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gsetwswindow\n");
}
viewport.xmin = 0.0;
viewport.ymin = 0.0;
viewport.xmax = 1.0;
viewport.ymax = wsWindow.ymax / wsWindow.xmax;
if (inPtr->err_ctr < (err = gsetviewport(1, &viewport)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gsetviewport\n");
}
window.xmin = 0.0;
window.ymin = 0.0;
window.xmax = display.raster.x - 1;
window.ymax = display.raster.y - 1;
if (inPtr->err_ctr < (err = gsetwindow(1, &window)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gsetwindow\n");
}
if (inPtr->err_ctr < (err = gselntran(1)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gselntran\n");
}
if (inPtr->err_ctr < (err = gclearws(wkstid, GALWAYS)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gclearws\n");
}
ginqmaxwssttables(inPtr->wsType, &wstables, &error);
if (error != E_NO_ERROR)
fprintf(fp, "Wrong return value from gInqMaxWSStTables\n");
if (cofac.coavail == GCOLOUR)
{
numColors = 256 / wstables.colour;
dtmp1 = MIN_INTENSITY;
for (index = 0; index < 256; index++)
{
if (! (index % numColors))
{
dtmp2 = index;
dtmp3 = (255.0 - dtmp2) / 255.0;
color = pow(dtmp1, dtmp3);
rgb.red = rgb.green = rgb.blue = 1.0 - color;
rayColorIndex = wstables.colour - 1 - (index / numColors);
if (inPtr->err_ctr < (err = gsetcolourrep(wkstid,
rayColorIndex, &rgb)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gsetcolourrep\n");
}
}
}
}
if (inPtr->err_ctr < (err = gcellarray(&rayRectangle, &dimensions,
colors)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gcellarray\n");
}
if (cofac.coavail == GMONOCHROME)
fprintf(fp, "End drawing ray traced picture\n\n");
else
fprintf(fp, "End drawing grey-scale ray traced picture\n\n");
/* return if mono workstation */
if (cofac.coavail == GMONOCHROME)
return;
/* continue if color workstation */
if (inPtr->pause == 'y')
{
fprintf(fp, "Display abstract ray traced picture? [y/n] ");
gets(response);
if (response[0] != 'y')
return;
}
for (i = 0; i < cofac.predefined; i++)
{
ginqpredcolourrep(inPtr->wsType, i, &cobundl, &error);
if (error != E_NO_ERROR)
fprintf(fp, "Wrong return value from gInqPredColourRep\n");
if (inPtr->err_ctr < (err =
gsetcolourrep(inPtr->wkstid, i, &cobundl)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gsetcolourrep\n");
}
}
ginqmaxwssttables(inPtr->wsType, &wstables, &error);
if (error!=E_NO_ERROR)
fprintf(fp, "Wrong return value from gInqMaxWSStTables\n");
cobundl.red = cobundl.green = cobundl.blue = 0.0;
for (i = cofac.predefined; i < wstables.colour; i++)
{
if (inPtr->err_ctr < (err =
gsetcolourrep(inPtr->wkstid, i, &cobundl)))
{
inPtr->err_ctr = err;
fprintf(fp, "0 returned from gsetcolourrep\n");
}
}
fprintf(fp, "Abstract ray traced picture should be visible\n\n");
return;
}