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-2010, 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 _WRITE3D_C
37
#include "openaxiom-c-macros.h"
38
39
#include <stdio.h>
40
#include <stdlib.h>
41
42
#include "header.h"
43
#include "write.h"
44
#include "mode.h"
45
46
47
#include "pixmap.h"
48
#include "XShade.h"
49
#include "Gfun.H1"
50
51
#include "all_3d.H1"
52
53
/* upper limit as to how many kinds of files could be written (numBits-1) */
54
#define numBits (8*sizeof(int))
55
#define StellarColors 9
56
57
int
58
writeViewport (int thingsToWrite)
59
{
60
61
int i, j, k, ii, *anIndex;
62
LLPoint *anLLPoint;
63
LPoint *anLPoint;
64
viewTriple *aPt;
65
XWindowAttributes vwInfo;
66
FILE *viewDataFile;
67
char viewDirName[80], viewDataFilename[80],
68
viewBitmapFilename[80], viewPixmapFilename[80],
69
command[80];
70
71
XGetWindowAttributes(dsply,viewport->titleWindow,&vwInfo);
72
sprintf(viewDirName,"%s%s",filename,".VIEW");
73
sprintf(command,"%s%s%s","rm -r ",viewDirName," > /dev/null 2>&1");
74
system(command);
75
sprintf(command,"%s%s%s","mkdir ",viewDirName," > /dev/null 2>&1");
76
system(command);
77
if (0) {
78
fprintf(stderr," Error: Cannot create %s\n",viewDirName);
79
return(-1);
80
} else {
81
82
/*** Create the data file ***/
83
sprintf(viewDataFilename,"%s%s",viewDirName,"/data");
84
if ((viewDataFile = fopen(viewDataFilename,"w")) == NULL) {
85
fprintf(stderr," Error: Cannot create %s\n",viewDataFilename);
86
perror("fopen");
87
return(-1);
88
} else {
89
/*** write out the view3DStruct stuff ***/
90
fprintf(viewDataFile,"%d\n",viewData.typeOf3D);
91
fprintf(viewDataFile,"%g %g %g %g %g %g\n",
92
viewData.xmin,viewData.xmax,viewData.ymin,viewData.ymax,
93
viewData.zmin,viewData.zmax);
94
fprintf(viewDataFile,"%s\n",viewport->title);
95
fprintf(viewDataFile,"%g %g %g %g %g %g %g %g\n",viewport->deltaX,
96
viewport->deltaY,viewport->scale,
97
viewport->scaleX,viewport->scaleY,viewport->scaleZ,
98
viewport->theta,viewport->phi);
99
fprintf(viewDataFile,"%d %d %d %d\n",vwInfo.x,vwInfo.y,vwInfo.width,
100
vwInfo.height);
101
fprintf(viewDataFile,"%d %d %d %d %d %d %d\n",viewport->haveControl,
102
viewData.style, viewport->axesOn,
103
viewport->hueOffset,viewport->numberOfHues,
104
viewport->diagonals, viewData.outlineRenderOn);
105
fprintf(viewDataFile,"%g %g %g %g\n",viewport->lightVector[0],
106
viewport->lightVector[1], viewport->lightVector[2],
107
viewport->translucency);
108
fprintf(viewDataFile,"%d %g\n",viewData.perspective,
109
viewData.eyeDistance);
110
111
/* write out the generalized 3D components */
112
fprintf(viewDataFile,"%d\n",viewData.numOfPoints);
113
for (i=0; i<viewData.numOfPoints; i++) {
114
aPt = refPt3D(viewData,i);
115
fprintf(viewDataFile,"%g %g %g %g\n",aPt->x, aPt->y, aPt->z, aPt->c);
116
}
117
fprintf(viewDataFile,"%d\n",viewData.lllp.numOfComponents);
118
anLLPoint = viewData.lllp.llp;
119
for (i=0; i<viewData.lllp.numOfComponents; i++,anLLPoint++) {
120
fprintf(viewDataFile,"%d %d\n",anLLPoint->prop.closed,
121
anLLPoint->prop.solid);
122
fprintf(viewDataFile,"%d\n",anLLPoint->numOfLists);
123
anLPoint = anLLPoint->lp;
124
for (j=0; j<anLLPoint->numOfLists; j++,anLPoint++) {
125
fprintf(viewDataFile,"%d %d\n",anLPoint->prop.closed,
126
anLPoint->prop.solid);
127
fprintf(viewDataFile,"%d\n",anLPoint->numOfPoints);
128
anIndex = anLPoint->indices;
129
for (k=0; k<anLPoint->numOfPoints; k++,anIndex++) {
130
fprintf(viewDataFile,"%d\n",*anIndex);
131
} /* for points in LPoints (k) */
132
} /* for LPoints in LLPoints (j) */
133
} /* for LLPoints in LLLPoints (i) */
134
fclose(viewDataFile);
135
} /* else was able to open file under the given filename */
136
137
/* write out special files */
138
for (ii=1; ii<numBits; ii++) { /* write.h is one-based */
139
if (thingsToWrite & (1<<ii)) {
140
switch (ii) {
141
case Bitmap:
142
/*** Create the pixmap (bitmaps need leaf name) ***/
143
sprintf(viewBitmapFilename,"%s%s%s",viewDirName,"/","image.bm");
144
XGetWindowAttributes(dsply,viewport->viewWindow,&vwInfo);
145
XWriteBitmapFile(dsply,viewBitmapFilename,
146
viewport->titleWindow,vwInfo.width,
147
vwInfo.height+vwInfo.border_width+20,-1,-1);
148
break;
149
150
case Pixmap:
151
/*** Create the pixmap (bitmaps need leaf name) ***/
152
sprintf(viewPixmapFilename,"%s%s%s",viewDirName,"/","image.xpm");
153
XGetWindowAttributes(dsply,viewport->viewWindow,&vwInfo);
154
write_pixmap_file(dsply,scrn,viewPixmapFilename,
155
viewport->titleWindow,0,0,vwInfo.width,
156
vwInfo.height+titleHeight);
157
break;
158
159
case Image:
160
/*** Create the image (bitmaps need leaf name) ***/
161
writeImage = yes;
162
sprintf(viewPixmapFilename,"%s%s%s",viewDirName,"/","image.xpm");
163
XResizeWindow(dsply,viewport->titleWindow,300,300+titleHeight);
164
XResizeWindow(dsply,viewport->viewWindow,300,300);
165
viewport->hueTop = totalHues-1; viewport->hueOffset = 0;
166
viewport->numberOfHues = viewport->hueTop - viewport->hueOffset;
167
firstTime = 1;
168
if (viewData.style == transparent) {
169
viewData.style = render;
170
viewData.outlineRenderOn = 1;
171
} else {
172
if (viewData.style == render) viewData.outlineRenderOn = 1;
173
}
174
drawViewport(Xoption);
175
writeTitle();
176
XGetWindowAttributes(dsply,viewport->viewWindow,&vwInfo);
177
write_pixmap_file(dsply,scrn,viewPixmapFilename,
178
viewport->titleWindow,0,0,vwInfo.width,
179
vwInfo.height+titleHeight);
180
viewport->monoOn = 1;
181
maxGreyShade = XInitShades(dsply,scrn);
182
firstTime = 1;
183
drawViewport(Xoption);
184
writeTitle();
185
sprintf(viewBitmapFilename,"%s%s%s",viewDirName,"/","image.bm");
186
XWriteBitmapFile(dsply,viewBitmapFilename,
187
viewport->titleWindow,vwInfo.width,
188
vwInfo.height+vwInfo.border_width+20,-1,-1);
189
190
writeImage = no;
191
break;
192
193
case Postscript:
194
/*** Create postscript output for viewport (in axiom3D.ps) ***/
195
sprintf(PSfilename,"%s%s",viewDirName,"/axiom3D.ps");
196
if (PSInit(viewport->viewWindow,viewport->titleWindow) == psError)
197
return(-1);
198
drawViewport(PSoption); /* write new script file in /tmp */
199
if (PSCreateFile(viewBorderWidth,viewport->viewWindow,
200
viewport->titleWindow, viewport->title) == psError)
201
return(-1); /* concat script & proc into axiom3D.ps */
202
break;
203
} /* switch on ii */
204
} /* if thingsToWrite >> ii */
205
} /* for ii */
206
207
return(0);
208
} /* else create directory okay */
209
210
}
211
212