VR-Forces 4.8 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
trpage_write.h
Go to the documentation of this file.
1 /* ************************
2  Copyright Terrain Experts Inc.
3  Terrain Experts Inc (TERREX) reserves all rights to this source code
4  unless otherwise specified in writing by the President of TERREX.
5  This copyright may be updated in the future, in which case that version
6  supercedes this one.
7  -------------------
8  Terrex Experts Inc.
9  4400 East Broadway #314
10  Tucson, AZ 85711
11  info@terrex.com
12  Tel: (520) 323-7990
13  ************************
14  */
15 
16 #ifndef _txpage_write_h_
17 #define _txpage_write_h_
19 
20 /* trpage_write.h
21  Classes that are used to write paging archives.
22  */
23 
25 #include <osgdb_vrftxp/trpage_io.h>
28 
29 /* Geometry Stats
30  Used with a Geometry Helper to keep track of what go built.
31  {group:Archive Writing}
32  */
34 public:
35  trpgwGeomStats(void);
36  ~trpgwGeomStats(void);
37 
38  int totalTri;
39 
40  int totalQuad;
41 
46 
47  int numStrip;
48  int numFan;
49 
50  int stripStat[15];
51  int fanStat[15];
52 
53  int stripGeom;
54  int fanGeom;
55  int bagGeom;
56 
58 
60  inline void AddStripStat(int val) { stripStat[MIN(14,val)]++; totalStripTri += val; totalTri += val; numStrip++;}
61  inline void AddFanStat(int val) { fanStat[MIN(14,val)]++; totalFanTri += val; totalTri += val; numFan++;}
62  inline void AddBagStat(int val) { totalBagTri += val; totalTri += val;}
63  inline void AddQuadStat(int val) { totalQuad += val; }
64 };
65 
66 /* Geometry Helper
67  Collects up geometry and tries to form triangle strips, fans,
68  and groups of triangles.
69  Right now this looks for a very careful ordering. If that ordering
70  isn't there you won't get useful tristrips or fans. You can, however
71  use this class as a starting point and build something more akin
72  to the geometry builder in Performer.
73  {group:Archive Writing}
74  */
76 public:
77  trpgwGeomHelper(void);
78  virtual ~trpgwGeomHelper(void);
79  enum {UseDouble,UseFloat};
80  trpgwGeomHelper(trpgWriteBuffer *,int dataType=UseDouble);
81  void init(trpgWriteBuffer *,int dataType=UseDouble);
82  virtual void SetMode(int);
83  virtual void Reset(void);
85  virtual void StartPolygon(void);
86  virtual void EndPolygon(void);
87  virtual void ResetPolygon(void);
88  virtual void SetColor(trpgColor &);
91  virtual void SetTexCoord(trpg2dPoint &);
92  virtual void AddTexCoord(trpg2dPoint &);
93  virtual void SetNormal(trpg3dPoint &);
94  virtual void SetMaterial(int32);
95  virtual void AddMaterial(int32);
96  virtual void AddVertex(trpg3dPoint &);
98 
100  virtual void FlushGeom(void);
101 
103  virtual void GetZMinMax(double &min,double &max);
104 
106  trpgwGeomStats *GetStats(void) { return &stats; }
107 protected:
108  int mode;
109  int dataType;
111 
112  /* Builds strips and fans from the triangle array.
113  We (TERREX) are assuming a certain ordering in our vertex array
114  because we do this optimization elsewhere. This won't work well
115  for anyone else. What you will need to do if you want good
116  performance is to implement a more generic form of this method.
117  All you should have to do is override Optimize(). You've
118  got the triangle arrays and a guarantee that the triangles
119  have the same material. All you really need is a decent fan/strip
120  algorithm.
121  */
122  virtual void Optimize(void);
123 
125  virtual void ResetTri(void);
126 
128  trpgGeometry strips,fans,bags;
129 
131  std::vector<int32> matTri;
132  std::vector<trpg2dPoint> tex;
133  std::vector<trpg3dPoint> norm,vert;
135  std::vector<int32> matPoly;
136  std::vector<trpg2dPoint> polyTex;
137  std::vector<trpg3dPoint> polyNorm,polyVert;
139  std::vector<trpg2dPoint> tmpTex;
142 
145 
147  double zmin,zmax;
148 };
149 
150 /* Image Write Helper.
151  Used to manage textures being added to a TerraPage archive.
152  It can write Local and Tile Local textures and also manages
153  the names of External textures (but you have to write those yourself).
154  */
156 public:
158  trpgwImageHelper(trpgEndian ness,char *dir,trpgTexTable &,bool separateGeoTypical);
160  virtual void Init(trpgEndian ness,char *dir,trpgTexTable &,bool separateGeoTypical);
161 
162  virtual ~trpgwImageHelper(void);
163 
165  virtual bool AddExternal(char *name,int &texID,bool lookForExisting=true);
166 
167  /* Adds an entry to the texture table for a local texture and
168  writes the data for that texture out to one of our texture
169  archive files.
170  */
171  virtual bool AddLocal(char *name,trpgTexture::ImageType type,int sizeX,int sizeY,bool isMipmap,char *data,int &texID,bool deferWrite);
172 
173  /* Replaces texture table information for a local texture and
174  writes the data for that texture out to one of our texture
175  archive files.
176  Up to you to ensure data is appropriate for the texture.
177  */
178  virtual bool ReplaceLocal(char *data,int &texID);
179 
180  /* Write a Tile Local texture out to one of our texture archive files.
181  Also creates a texture template, if necessary.
182  Caller is responsible for creating the Tile Local material and
183  placing it in the appropriate tile.
184  */
185  virtual bool AddTileLocal(char *name,trpgTexture::ImageType type,int sizeX,int sizeY,bool isMipmap,char *data, int &texID,trpgwAppAddress &addr);
186 
187  /* Sets the maximum advised length for a texture archive file.
188  Once the length is exceeded, the image write helper will move
189  on to the next tex file.
190  */
191  virtual void SetMaxTexFileLength(int len);
192 
193  /* Texture archive files are managed by this class and will
194  be created as needed. This method will increment to
195  the next texture file.
196  Note: This may create more files than we really need.
197  */
198  virtual trpgwAppFile * IncrementTextureFile(bool geotyp);
199 
200  /* Close the current texture file and go on to one with the
201  given base name. This is used for regenerate.
202  */
203  virtual bool DesignateTextureFile(int);
204 
206  virtual bool Flush(void);
207 
209  virtual trpgwAppFile* GetNewWAppFile(trpgEndian inNess,const char *fileName,bool reuse=false);
210 
212  bool WriteToArchive(const trpgTexture &tex,char *data,trpgwAppAddress &addr,bool geotyp=false);
214 
215 protected:
216 
217 
219  char dir[1024];
221  std::vector<int> texFileIDs;
223  std::vector<int> geotypFileIDs;
227 };
228 
229 /* Paging Archive
230  This is a writeable paging archive.
231  It organizes where things get written and how.
232  {group:Archive Writing}
233  */
235 public:
237  enum TileMode {TileLocal,TileExternal,TileExternalSaved};
238 
241  trpgwArchive(char *baseDir,char *name,trpg2dPoint &ll,trpg2dPoint &ur, int majorVer=TRPG_VERSION_MAJOR, int minorVer=TRPG_VERSION_MINOR);
242  virtual void Init(char *baseDir,char *name,trpg2dPoint &ll,trpg2dPoint &ur, int majorVer=TRPG_VERSION_MAJOR, int minorVer=TRPG_VERSION_MINOR);
244  trpgwArchive(trpgEndian ness=LittleEndian,TileMode tileMode=TileLocal,int majorVer=TRPG_VERSION_MAJOR, int minorVer=TRPG_VERSION_MINOR);
245  virtual void Init(trpgEndian ness=LittleEndian,TileMode tileMode=TileLocal,int majorVer=TRPG_VERSION_MAJOR, int minorVer=TRPG_VERSION_MINOR);
247  trpgwArchive(int ) {;};
248  virtual ~trpgwArchive(void);
249 
252  virtual void SetMaxTileFileLength(int len);
253 
255  virtual bool SetHeader(const trpgHeader &);
256  virtual bool SetMaterialTable(const trpgMatTable &);
257  virtual bool SetTextureTable(const trpgTexTable &);
258  virtual bool SetModelTable(const trpgModelTable &);
259  virtual bool SetLightTable(const trpgLightTable &);
260  virtual bool SetRangeTable(const trpgRangeTable &);
261  virtual bool SetLabelPropertyTable(const trpgLabelPropertyTable &);
262  virtual bool SetSupportStyleTable(const trpgSupportStyleTable &);
263  virtual bool SetTextStyleTable(const trpgTextStyleTable &);
264 
266  virtual trpgHeader *GetHeader();
267  virtual trpgMatTable *GetMatTable();
268  virtual trpgTexTable *GetTextureTable();
269  virtual trpgModelTable *GetModelTable();
270  virtual trpgLightTable *GetLightTable();
271  virtual trpgRangeTable *GetRangeTable();
272  virtual trpgLabelPropertyTable *GetLabelPropertyTable();
273  virtual trpgTextStyleTable *GetTextStyleTable();
274  virtual trpgSupportStyleTable *GetSupportStyleTable();
275 
276 
277 
278  virtual bool IncrementTileFile(void);
279  virtual bool DesignateTileFile(int);
280 
283 
284  virtual bool OpenFile(const char *,const char *);
285  virtual void CloseFile(void);
286  virtual bool WriteHeader(void);
287  virtual bool CheckpointHeader(void);
288  virtual bool WriteTile(unsigned int,unsigned int,unsigned int,float zmin,float zmax,
289  const trpgMemWriteBuffer *,const trpgMemWriteBuffer *, int32& fileId, int32& fileOffset);
291 
292  bool isValid(void) const;
293  const char *getErrMess() const;
294  char* getDir(void){return dir;};
295  virtual trpgwImageHelper* GetNewWImageHelper(trpgEndian ness,char *dir,trpgTexTable &);
296  virtual trpgwAppFile* GetNewWAppFile(trpgEndian inNess,const char *fileName,bool reuse=false);
297  virtual trpgr_Archive* GetArchiveReader() {return new trpgr_Archive();};
298  virtual int32 WriteHeaderData(const char *dataPtr,int32 length,FILE *filehandle);
299  virtual int32 GetMagicNumber() {return TRPG_MAGIC;};
300 protected:
302  bool isRegenerate;
303 
306  public:
307  int x,y,lod;
308  float zmin,zmax;
310  };
311  class TileFile {
312  public:
313  int id;
314  std::vector<TileFileEntry> tiles;
315  };
316 
317  trpgEndian ness,cpuNess;
318  int majorVersion, minorVersion;
320  char dir[1024];
321 
323 
333 
334 
336 
337  int numLod;
339 
342 
343  std::vector<TileFile> tileFiles;
344 
345  std::vector<TileFileEntry> externalTiles;
346 
348 
351 
352  FILE *fp;
353 
355 
356  mutable char errMess[512];
357 };
358 
359 #endif
Definition: trpage_write.h:155
Definition: trpage_geom.h:2076
trpgEndian ness
Merge block textable into a master.
Definition: trpage_write.h:218
Definition: trpage_geom.h:2951
trpgWriteBuffer * buf
Definition: trpage_write.h:110
trpgwArchive(int)
dummy constructor, does nothing so subclasses can have more control
Definition: trpage_write.h:247
int stripGeom
Fan length stats.
Definition: trpage_write.h:53
int totalBagTri
triangles in fans
Definition: trpage_write.h:45
trpgGeometry strips
Collections of geometry.
Definition: trpage_write.h:128
double zmin
Keeps track of min and max z values.
Definition: trpage_write.h:147
trpgEndian
Used to specify machine endianess.
Definition: trpage_io.h:314
Definition: trpage_write.h:75
trpgwImageHelper()
Definition: trpage_write.h:157
#define DT_DLL_osgdb_vrftxp
Contains DLL export macros.
Definition: osgdb_vrftxpDefines.h:25
int mode
Definition: trpage_write.h:108
Definition: trpage_io.h:314
trpgwAppFile * geotypFile
Definition: trpage_write.h:224
int maxTexFileLen
Definition: trpage_write.h:226
trpgwGeomStats * GetStats(void)
Get statistics for whatever we built.
Definition: trpage_write.h:106
std::vector< trpg2dPoint > polyTex
Definition: trpage_write.h:136
trpgMatTable matTable
Definition: trpage_write.h:325
trpg3dPoint tmpNorm
Definition: trpage_write.h:140
{secret}
Definition: trpage_write.h:33
std::vector< int32 > matPoly
Data arrays for a polygon.
Definition: trpage_write.h:135
int stateChanges
Same for bags.
Definition: trpage_write.h:57
Definition: trpage_geom.h:1438
int fanGeom
Number of seperate trpgGeometry nodes for strips.
Definition: trpage_write.h:54
trpgwGeomStats stats
Geometry status built up as we go.
Definition: trpage_write.h:144
int totalFanTri
triangles in strips
Definition: trpage_write.h:44
#define MIN(x, y)
Macros we may need.
Definition: trpage_io.h:36
trpgTextStyleTable textStyleTable
Definition: trpage_write.h:330
char * getDir(void)
Definition: trpage_write.h:294
trpgTileTable tileTable
Definition: trpage_write.h:335
TileMode tileMode
Definition: trpage_write.h:338
#define TRPG_VERSION_MAJOR
Current TerraPage major version.
Definition: trpage_io.h:47
Definition: trpage_geom.h:1055
std::vector< trpg3dPoint > vert
Definition: trpage_write.h:133
trpgLabelPropertyTable labelPropertyTable
Definition: trpage_write.h:332
std::vector< trpg2dPoint > tex
Definition: trpage_write.h:132
virtual trpgr_Archive * GetArchiveReader()
Definition: trpage_write.h:297
int totalStripTri
Total # of quads.
Definition: trpage_write.h:43
trpg2iPoint addOffset
This offset is used when we&#39;re adding to an existing archive.
Definition: trpage_write.h:350
int32 offset
Definition: trpage_write.h:309
int y
Definition: trpage_write.h:307
Definition: trpage_geom.h:1616
trpgTexTable texTable
Definition: trpage_write.h:326
Definition: trpage_io.h:652
Definition: trpage_geom.h:1226
int numLod
Definition: trpage_write.h:337
int id
Definition: trpage_write.h:313
trpgwAppFile * tileFile
Definition: trpage_write.h:340
trpgSupportStyleTable supportStyleTable
Definition: trpage_write.h:331
Definition: trpage_io.h:376
std::vector< int > geotypFileIDs
Definition: trpage_write.h:223
int numFan
Number of distinct strips.
Definition: trpage_write.h:48
Definition: trpage_io.h:265
Definition: trpage_read.h:185
void AddStripStat(int val)
Number of distinct material switches.
Definition: trpage_write.h:60
int maxTileFileLen
Definition: trpage_write.h:347
Definition: trpage_io.h:561
Definition: trpage_io.h:299
Definition: trpage_geom.h:2862
std::vector< int32 > matTri
Temporary data arrays for triangles/quads.
Definition: trpage_write.h:131
trpgRangeTable rangeTable
Definition: trpage_write.h:329
bool firstHeaderWrite
Definition: trpage_write.h:354
int totalTri
Definition: trpage_write.h:38
void AddFanStat(int val)
Definition: trpage_write.h:61
float zmin
Identifying info for tile.
Definition: trpage_write.h:308
trpgEndian ness
Definition: trpage_write.h:317
std::vector< trpg2dPoint > tmpTex
Single points.
Definition: trpage_write.h:139
Definition: trpage_io.h:632
void AddBagStat(int val)
Definition: trpage_write.h:62
std::vector< int > texFileIDs
Definition: trpage_write.h:221
int bagGeom
Same for fans.
Definition: trpage_write.h:55
#define TRPG_MAGIC
File header Magic Number.
Definition: trpage_io.h:44
#define TRPG_VERSION_MINOR
Current TerraPage minor version.
Definition: trpage_io.h:49
std::vector< TileFile > tileFiles
Definition: trpage_write.h:343
Definition: trpage_geom.h:48
bool separateGeoTypical
Definition: trpage_write.h:225
bool isValid(void) const
Returns the state of the valid flag, or can be overriden by a subclass to do a more complex check...
Definition: trpage_geom.h:3045
Definition: trpage_geom.h:903
Definition: trpage_io.h:323
Definition: trpage_geom.h:1680
Definition: trpage_io.h:278
trpgModelTable modelTable
Definition: trpage_write.h:327
int tileFileCount
Definition: trpage_write.h:341
std::vector< TileFileEntry > tiles
Definition: trpage_write.h:314
ImageType
Definition: trpage_geom.h:1252
std::vector< trpg3dPoint > polyVert
Definition: trpage_write.h:137
DT_DLL_DEBUGDRAWRENDERER void init(makVrv::DtDe &de)
Work function for the plugin initialization.
int numStrip
loose triangles
Definition: trpage_write.h:47
trpgLightTable lightTable
Definition: trpage_write.h:328
Definition: trpage_write.h:234
void AddQuadStat(int val)
Definition: trpage_write.h:63
trpgHeader header
Directory where we&#39;re doing all this.
Definition: trpage_write.h:324
TileMode
Tiles can be stored as individual files (External) or grouped together (Local)
Definition: trpage_write.h:237
Definition: trpage_geom.h:1119
#define TX_EXDECL
Goes before &quot;class&quot; to handle DLL export in windows.
Definition: trdll.h:69
FILE * fp
Definition: trpage_write.h:352
std::vector< TileFileEntry > externalTiles
Definition: trpage_write.h:345
trpgTexTable * texTable
Definition: trpage_write.h:220
trpgColor tmpCol
Definition: trpage_write.h:141
int minorVersion
Definition: trpage_write.h:318
Definition: trpage_write.h:311
trpgwAppFile * texFile
Definition: trpage_write.h:222
int dataType
Definition: trpage_write.h:109
int totalQuad
Total # of triangles.
Definition: trpage_write.h:40
Definition: trpage_io.h:285
Used to keep track of which tiles are in which file.
Definition: trpage_write.h:305

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)