Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
/*
2
Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.
3
All rights reserved.
4
Copyright (C) 2007-2008, Gabriel Dos Reis.
5
All rights reserved.
6
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are
9
met:
10
11
- Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
14
- Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in
16
the documentation and/or other materials provided with the
17
distribution.
18
19
- Neither the name of The Numerical Algorithms Group Ltd. nor the
20
names of its contributors may be used to endorse or promote products
21
derived from this software without specific prior written permission.
22
23
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
27
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*/
35
36
#define _SPOONCOMP_C
37
38
#include <stdlib.h>
39
#include <unistd.h>
40
#include <string.h>
41
42
#include "open-axiom.h"
43
#include "viewAlone.h"
44
#include "mode.h"
45
46
#include "util.H1"
47
#include "cfuns.h"
48
#include "all_alone.H1"
49
50
using namespace OpenAxiom;
51
52
53
54
/* This file forks a child process and exits the parent. It
55
has the same general form as ../viewman/funView3D() and so
56
changes there may require similar changes here. */
57
58
void
59
spoonView3D(int type)
60
{
61
62
int i,j,k,code,pipe0[2],pipe1[2];
63
char envAXIOM[100],runView[100];
64
LLPoint *anLLPoint;
65
LPoint *anLPoint;
66
int *anIndex;
67
68
sprintf(errorStr,"%s","creating pipes");
69
check(pipe(pipe0));
70
check(pipe(pipe1));
71
switch(fork()) {
72
case -1:
73
fprintf(stderr,"can't create a child process\n");
74
fprintf(stderr,"you may have too many processes running\n");
75
exit(-1);
76
case 0:
77
/* Child */
78
sprintf(errorStr,"%s",
79
"(viewAlone) mapping of pipes to standard I/O for view3D");
80
check(dup2(pipe0[0],0));
81
check(dup2(pipe1[1],1));
82
close(pipe0[0]);
83
close(pipe0[1]);
84
close(pipe1[0]);
85
close(pipe1[1]);
86
87
sprintf(errorStr,"%s",
88
"(viewAlone) execution of the ThreeDimensionalViewport process");
89
sprintf(envAXIOM,"%s",oa_getenv("AXIOM"));
90
sprintf(runView,"%s%s",envAXIOM,"/lib/view3D");
91
check(execl(runView,runView, (char*) NULL));
92
fprintf(stderr,"Could not execute view3D!\n");
93
exit(-1);
94
default:
95
/* Parent */
96
97
viewP.viewType = type;
98
99
/* set up pipes to child process */
100
close(pipe0[0]);
101
close(pipe1[1]);
102
viewP.viewIn = pipe1[0];
103
viewP.viewOut = pipe0[1];
104
105
if (viewP.viewIn <0) {
106
fprintf(stderr,
107
"can't set up pipes to viewport process. Try again.\n");
108
return;
109
} else {
110
code = read(viewP.viewIn,&ack,intSize);
111
if (code < 0) {
112
fprintf(stderr,"can't read from viewport process pipe. Try again.\n");
113
return;
114
}
115
}
116
117
makeView3DFromFileData(type);
118
/* tell child it is to be a stand alone program */
119
i = yes;
120
fprintf(stderr," Transmitting data to viewport...\n");
121
write(viewP.viewOut,&i,intSize);
122
write(viewP.viewOut,&doView3D,sizeof(view3DStruct));
123
i = strlen(doView3D.title)+1;
124
write(viewP.viewOut,&i,intSize); /* tell the length of
125
the title to child */
126
write(viewP.viewOut,doView3D.title,i); /* tell the title
127
to the child, child */
128
write(viewP.viewOut,&(doView3D.lightVec[0]),floatSize);
129
write(viewP.viewOut,&(doView3D.lightVec[1]),floatSize);
130
write(viewP.viewOut,&(doView3D.lightVec[2]),floatSize);
131
132
write(viewP.viewOut,&(doView3D.numOfPoints),intSize);
133
for (i=0; i<doView3D.numOfPoints; i++) {
134
write(viewP.viewOut,&(refPt(doView3D,i)->x),floatSize);
135
write(viewP.viewOut,&(refPt(doView3D,i)->y),floatSize);
136
write(viewP.viewOut,&(refPt(doView3D,i)->z),floatSize);
137
write(viewP.viewOut,&(refPt(doView3D,i)->c),floatSize);
138
}
139
140
/* send generalized 3D components */
141
write(viewP.viewOut,&(doView3D.lllp.numOfComponents),intSize);
142
anLLPoint = doView3D.lllp.llp;
143
for (i=0; i<doView3D.lllp.numOfComponents; i++,anLLPoint++) {
144
write(viewP.viewOut,&(anLLPoint->prop.closed),intSize);
145
write(viewP.viewOut,&(anLLPoint->prop.solid),intSize);
146
write(viewP.viewOut,&(anLLPoint->numOfLists),intSize);
147
anLPoint = anLLPoint->lp;
148
for (j=0; j<anLLPoint->numOfLists; j++,anLPoint++) {
149
write(viewP.viewOut,&(anLPoint->prop.closed),intSize);
150
write(viewP.viewOut,&(anLPoint->prop.solid),intSize);
151
write(viewP.viewOut,&(anLPoint->numOfPoints),intSize);
152
anIndex = anLPoint->indices;
153
for (k=0; k<anLPoint->numOfPoints; k++,anIndex++)
154
write(viewP.viewOut,anIndex,intSize);
155
} /* for LPoints in LLPoints (j) */
156
} /* for LLPoints in LLLPoints (i) */
157
fprintf(stderr," Done.\n");
158
159
/*** get acknowledge from viewport */
160
code = read(viewP.viewIn,&(viewP.viewWindow),sizeof(Window));
161
openaxiom_sleep(1); /* wait a second...*/
162
exit(0);
163
164
} /* switch */
165
166
} /* spoonView3D() */
167
168
169
void
170
makeView3DFromFileData(int type)
171
{
172
173
int i,j,k;
174
char title[256];
175
LLPoint *anLLPoint;
176
LPoint *anLPoint;
177
viewTriple *aPoint;
178
int *anIndex;
179
180
/* fscanf(doView3D,""); */
181
/* read in the view3DStruct stuff */
182
/* &view3DType already read */
183
doView3D.typeOf3D = type;
184
fscanf(viewFile,"%f %f %f %f %f %f\n",
185
&(doView3D.xmin),
186
&(doView3D.xmax),
187
&(doView3D.ymin),
188
&(doView3D.ymax),
189
&(doView3D.zmin),
190
&(doView3D.zmax));
191
192
fgets(title,256,viewFile);
193
if (!(doView3D.title = (char *)malloc((strlen(title)+1) *
194
sizeof(char)))) {
195
fprintf(stderr,"Ran out of memory (malloc) trying to get the title.\n");
196
exit(-1);
197
}
198
sprintf(doView3D.title,"%s",title);
199
/* put in a null terminator over the newline that the fgets reads */
200
doView3D.title[strlen(doView3D.title)-1] = '\0';
201
202
fscanf(viewFile,"%f %f %f %f %f %f %f %f\n",
203
&(doView3D.deltaX),
204
&(doView3D.deltaY),
205
&(doView3D.scale),
206
&(doView3D.scaleX),
207
&(doView3D.scaleY),
208
&(doView3D.scaleZ),
209
&(doView3D.theta),
210
&(doView3D.phi));
211
212
fscanf(viewFile,"%d %d %d %d\n",
213
&(doView3D.vX),
214
&(doView3D.vY),
215
&(doView3D.vW),
216
&(doView3D.vH));
217
fscanf(viewFile,"%d %d %d %d %d %d %d\n",
218
&(doView3D.showCP),
219
&(doView3D.style),
220
&(doView3D.AxesOn),
221
&(doView3D.hueOff),
222
&(doView3D.numOfHues),
223
&(doView3D.diagonals),
224
&(doView3D.outlineRenderOn));
225
fscanf(viewFile,"%f %f %f %f\n",
226
&(doView3D.lightVec[0]),
227
&(doView3D.lightVec[1]),
228
&(doView3D.lightVec[2]),
229
&(doView3D.translucency));
230
fscanf(viewFile,"%d %f\n",
231
&(doView3D.perspective),
232
&(doView3D.eyeDistance));
233
234
/* get generalized 3D components */
235
236
fscanf(viewFile,"%d\n",
237
&(doView3D.numOfPoints));
238
aPoint = doView3D.points = (viewTriple *)malloc(doView3D.numOfPoints*
239
sizeof(viewTriple));
240
for (i=0; i<doView3D.numOfPoints; i++, aPoint++)
241
fscanf(viewFile,"%g %g %g %g\n",
242
&(aPoint->x),
243
&(aPoint->y),
244
&(aPoint->z),
245
&(aPoint->c));
246
fscanf(viewFile,"%d\n",
247
&(doView3D.lllp.numOfComponents));
248
anLLPoint = doView3D.lllp.llp =
249
(LLPoint *)malloc(doView3D.lllp.numOfComponents*sizeof(LLPoint));
250
for (i=0; i<doView3D.lllp.numOfComponents; i++,anLLPoint++) {
251
fscanf(viewFile,"%d %d\n",
252
&(anLLPoint->prop.closed),
253
&(anLLPoint->prop.solid));
254
fscanf(viewFile,"%d\n",
255
&(anLLPoint->numOfLists));
256
anLPoint = anLLPoint->lp =
257
(LPoint *)malloc(anLLPoint->numOfLists*sizeof(LPoint));
258
for (j=0; j<anLLPoint->numOfLists; j++,anLPoint++) {
259
fscanf(viewFile,"%d %d\n",
260
&(anLPoint->prop.closed),
261
&(anLPoint->prop.solid));
262
fscanf(viewFile,"%d\n",
263
&(anLPoint->numOfPoints));
264
anIndex = anLPoint->indices =
265
(int *)malloc(anLPoint->numOfPoints*sizeof(int));
266
for (k=0; k<anLPoint->numOfPoints; k++,anIndex++) {
267
fscanf(viewFile,"%dn",anIndex);
268
} /* for points in LPoints (k) */
269
} /* for LPoints in LLPoints (j) */
270
} /* for LLPoints in LLLPoints (i) */
271
272
fclose(viewFile);
273
doView3D.scaleDown = no ;
274
}
275
276
277