fileReader.H
5.74 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
/******************************************************************************\
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: fileReader.H
* CLASS: FileReader
* DESCRIPTION: A class of file readers for each desired format
* AUTHOR: Mike Goslin
* CREATED: 2/7/95
* REVISIONS:
*
*******************************************************************************/
#ifndef _FILEREADER_HPP_
#define _FILEREADER_HPP_
#include <stdio.h>
#include "dataBase.H"
#include "lsb.h"
#include "fileWriter.H"
typedef unsigned char uchar;
class FileReader
{
protected:
FILE *file;
char fname[ID_LENGTH];
DataBase *dbase;
uint openFile(void) { if ((file = fopen(fname, "r")) == NULL)
return (0); else return (1); }
public:
virtual DataBase *Read(char *_fname) = 0;
};
#define NOMTLIND 4094
class FltReader : public FileReader
{
char *buffer,
*bufend;
long bufsize;
mgVertTable *vtable;
uint initHeaderBead(void);
uint loadFltFile(const char* name);
char *traverse(Bead *parent, char *tree, char *end, long depth);
char *traverseObj(char *ptr, char *end, long depth);
void traverseSubPoly(char **nptr, char *ptr, char *end, long depth);
char *traversePoly(mgPolygon *poly);
void LookAhead(char *ptr, mgComment **c, mgMatrix **m,
mgReplicate **r, mgLongID **hLongID);
public:
FltReader(void);
DataBase *Read(char *_fname);
};
#define NLOD 3
#define BUFFER_SIZE 256
#define PROGNAME "lsb2pp"
#define CURRENT_FILE_POSITION 1
#define FILE_BEGINNING 0
#define DEFAULT_COLOR_DELTA 5
typedef float Vec4[4];
typedef float Vec3[3];
typedef float Vec2[2];
class LsReader : public FileReader
{
int gStructCount;
int gPgFlags;
int fUsage;
int fPrependFileName2StructName;
int useLongData;
char outfname[ID_LENGTH];
FILE *outfile;
int doRadTxtr;
TxtrWriter *txtrWriter;
int levels,
deepestlevels; // Used for calculating texture values
uint leafNumber;
long textureFilePos;
ulong curTxtrId;
ulong curPolyId;
uint txtrIndex;
ulong txtrXoff,
txtrYoff;
uint doAvgFaceColor;
uint doColorPerVertPoly;
int minDepthForTexture,
colorDelta;
float area(Vec2 p0, Vec2 p1, Vec2 p2);
uint pointInPoly(Vec2 p0, Vec2 p1, Vec2 p2, Vec2 point);
int readSignature(FILE *fp);
void V_normalize(float v[3]);
int readHeader(FILE *fp, LSBheader *header);
int readMaterials(FILE *fp, ulong nmaterials, LSmaterial **materials);
int readLayers(FILE *fp, ulong nlayers, LSlayer **layers);
int readTextures(FILE *fp, ulong ntexturesinput, ulong ntextures,
LStexture **textures);
int readPatchLeaf(FILE *fp, ulong *verts, ulong *midVerts);
void initPatchNodes(LSpatchNode *node, ulong level, Vec3 *coords,
Vec2 *texCoords, ulong *lodPrimNums,
ulong *lodLevels, int nlods);
int readPatchCluster(FILE *fp, ushort *flags, Vec4 plane,
ulong *materialId, ulong *layerId,
ulong *textureId, ulong *numTopNodes,
ulong *numNodes, ulong *numTopVerts,
ulong *numVertices);
int loadPatchVertex(FILE *fp, Vec4 *color);
void triangleBuildTriIndex(LSpatchNode *node, ushort **curIndex);
void quadBuildTriIndex(LSpatchNode *node, ushort **curIndex);
void buildIndexForTris(LSpatchNode *node, ulong curLevel,
ulong maxLevel, ushort **curIndex);
void findColor(LSpatchNode *node, ulong curLevel, ulong maxLevel,
Vec3 sample, txtrData& value, Vec3 *coords, Vec4 *colors);
int loadTopPatchVertex(FILE *fp, Vec4 *color, Vec3 *coord,
Vec2 *texcoord);
LSpatchNode *loadPatchNodes(FILE *fp, LSpatchNode *root,
LSpatchNode **nodes,
LSpatchVertex *vertices);
int loadPatchClusters(FILE *fp, LSBheader *lsbHeader,
LSmaterial *materials, LSlayer *layers,
LStexture *textures, LSpatchCluster *clusters,
ulong *nTris);
public:
LsReader(void);
void enableRadTexture(void) { doRadTxtr = 1; }
void enableAvgFaceColor(void) { doAvgFaceColor = 1; }
void enableColorPerVertPoly(void) { doColorPerVertPoly = 1; }
void MinDepthForTexture(int value) { minDepthForTexture = value; }
void ColorDelta(int value) { colorDelta = value; }
DataBase *Read(char *_fname);
};
double Distance(Vec3 p0, Vec3 p1);
#endif