fileWriter.H
7.15 KB
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
/******************************************************************************\
Copyright 1995 The University of North Carolina at Chapel Hill.
All Rights Reserved.
Permission to use, copy, modify and distribute this software and its
documentation for educational, research and non-profit purposes, without
fee, and without a written agreement is hereby granted, provided that the
above copyright notice and the following three paragraphs appear in all
copies.
IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA
AT CHAPEL HILL BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE
UNIVERSITY OF NORTH CAROLINA HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
THE UNIVERSITY OF NORTH CAROLINA SPECIFICALLY DISCLAIM ANY WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HERUNDER IS
ON AN "AS IS" BASIS, AND THE UNIVERSITY OF NORTH CAROLINA HAS NO OBLIGATIONS
TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
The author may be contacted via:
US Mail: Mike Goslin
Department of Computer Science
Sitterson Hall, CB #3175
University of N. Carolina
Chapel Hill, NC 27599-3175
Phone: (919)962-1719
EMail: goslin@cs.unc.edu
*******************************************************************************/
/*******************************************************************************
* FILENAME: fileWriter.H
* CLASS: FileWriter
* DESCRIPTION: A class of file writers for each desired format
* AUTHOR: Mike Goslin
* CREATED: 2/7/95
* REVISIONS: 3/17/95 - Added lightscape writer (MPG)
*
*******************************************************************************/
#ifndef _FILEWRITER_HPP_
#define _FILEWRITER_HPP_
#include <stdio.h>
#include "dataBase.H"
#include "image.H"
typedef unsigned int uint;
typedef unsigned char uchar;
class FileWriter
{
protected:
FILE *file;
char fname[80];
DataBase *dbase;
uint openFile(void) { if ((file = fopen(fname, "w")) == NULL)
return (0); else return (1); }
public:
virtual uint Write(char *_fname) = 0;
};
/*******************************************************************************
* MultiGen Flight format file writer (.flt)
*******************************************************************************/
#define FLT_HEADER_LENGTH 4
#define FLT_HEADER_ID_LENGTH 8
#define FLT_HEADER_REVDATE_LENGTH 32
#define POLYGON_ID_LENGTH 8
class FltWriter : public FileWriter
{
void writeHeader(const mgHeader& header);
void writeColorTable(const mgColorTable& coltab);
void writeMaterialTable(const mgMaterialTable& mattab);
void writeTextureRef(const mgTextureRef& texref);
void writeVertex(mgVertSharedAbs* vert);
void writeVertex(mgVertSharedNorm* vert);
void writeVertex(mgVertSharedNormTex* vert);
void writeVertex(mgVertSharedAbsTex* vert);
uint writeVertexPool(const VertexTableBead* vtable);
void writeBead(Bead *bead);
void writeControl(ushort *type);
void traverse(Bead *bead);
public:
FltWriter(DataBase *_dbase);
uint Write(char *_fname);
};
/******************************************************************************** Lightscape preparation format file writer (.lp)
*******************************************************************************/
#define ATTR_DIFF_REFL 0x0001 // Diffuse Reflector
#define ATTR_DIFF_TRANS 0x0002 // Diffuse Transmittor
#define ATTR_SPEC_REFL 0x0004 // Specular Reflector
#define ATTR_SPEC_TRANS 0x0008 // Specular Transmittor
#define ATTR_GLOWING 0x0010 // Self-Emitted Luminance
#define ATTR_TEXTURED 0x0040 // Has a texture
#define TEXTURE_ABSOLUTE_SIZE_BIT 0x0001
#define TEXTURE_MIN_POINT 0
#define TEXTURE_MIN_LINEAR 1
#define TEXTURE_MIN_POINT_MM 2
#define TEXTURE_MIN_LINEAR_MM 3
#define TEXTURE_MIN_BILINEAR_MM 4
#define TEXTURE_MIN_TRILINEAR_MM 5
#define TEXTURE_MAG_POINT 0
#define TEXTURE_MAG_LINEAR 1
#define ENTITY_POLY 0x0004 // Set is entity is a polygon
#define ENTITY_INSTANCE 0x0001 // Set if entity is an instance
#define POLY_TEXATTR_INSTALLED 0x0800
#define POLY_TRIANGLE_BIT 0x0004
#define POLY_X_AXIS 0x0000
#define POLY_Y_AXIS 0x0001
#define POLY_Z_AXIS 0x0002
#define POLY_TWO_SIDED_BIT 0x1000
#define POLY_NOTARECEIVER_BIT 0x0100
#define POLY_NOTANOBSTACLE_BIT 0x0200
#define POLY_NOTAREFLECTOR_BIT 0x0400
#define POLY_WINDOW_BIT 0x2000
#define POLY_OPENING_BIT 0x4000
#define ATTRIBUTE_TRAVERSAL 1
#define BLOCK_TRAVERSAL 2
#define ENTITY_TRAVERSAL 0
#define MAX_VERTICES_PER_POLYGON 32
#define FUZZ_VALUE 10e-7
#define INFINITY 10e23
typedef struct attr {
short index;
struct attr *next;
} attribute;
typedef struct txinfo {
short index;
int number;
double avgsizeU,
avgsizeV;
struct txinfo *next;
} TexInfo;
class LsWriter : public FileWriter
{
int travType;
char *rootname;
attribute *attribList;
mgColorTable colTable;
TextureBead *texList;
VertexTableBead *vtxpool;
double maxExt[3],
minExt[3];
TexInfo *textureInfo;
void V_normalize(double v[]);
void writeDefaults(void);
void writeView(void);
void writeNaturalLight(void);
void writeTextureTable(void);
void writeAttributeTable(void);
void writeLayerTable(void);
void writeSourceTable(void);
void writeBlock(char *name);
void writeEntity(int flags, char *attribute=NULL);
void writePolygon(double p0[3], double p1[3], double p2[3],
char drawType, int textured);
void writePolygon(double p0[3], double p1[3], double p2[3],
double p3[3], char drawType, int textured);
void writeTextureOrientation(double v0[3], double v1[3]);
void writeInstance(char *blockname);
void writeGroupBlock(Bead *bead);
void procBead(Bead *bead);
void traverse(Bead *bead);
void indent(void);
short decodeAttribute(short color);
char *decodeTextureAttribute(short texture, char attribute[80]);
uint verifyPolygon(double vertices[MAX_VERTICES_PER_POLYGON][3],
int vtxcount);
void computeTexCoords(double verts[MAX_VERTICES_PER_POLYGON][3],
float tex[MAX_VERTICES_PER_POLYGON][2],
int vtxcount, double *v0, double *v1,
double& Uscale, double& Vscale);
int updateAvgTextureScale(short texture, double Uscale, double Vscale);
public:
LsWriter(DataBase *_dbase);
uint Write(char *_fname);
};
/******************************************************************************** SGI Texture-map File Writer (.rgb)
*******************************************************************************/
#define MAX_XSIZE 2048
#define MAX_YSIZE 2048
class TxtrWriter : public FileWriter
{
Image *image;
int putbyte(unsigned char val);
int putshort(unsigned short val);
int putlong(unsigned long val);
public:
TxtrWriter(void);
TxtrWriter(uint size);
~TxtrWriter();
uint Write(uint x, uint y, txtrData value);
uint Write(char *_fname);
};
#endif