trpage_print.cpp
来自「最新osg包」· C++ 代码 · 共 1,079 行 · 第 1/3 页
CPP
1,079 行
/* ************************ Copyright Terrain Experts Inc. Terrain Experts Inc (TERREX) reserves all rights to this source code unless otherwise specified in writing by the President of TERREX. This copyright may be updated in the future, in which case that version supercedes this one. ------------------- Terrex Experts Inc. 4400 East Broadway #314 Tucson, AZ 85711 info@terrex.com Tel: (520) 323-7990 ************************ */#include <osgDB/FileUtils>#include <stdlib.h>#include <stdio.h>#include <string.h>/* trpage_print.cpp Print out the contents of a TerraPage archive. This module provides an example of how to access each of the classes within a TerraPage archive.*/#include <trpage_print.h>/* ****************************************** Print Buffer implementation The print buffer is a way to dump debugging data out to a file (or console). You can make your own subclass of trpgPrintBuffer if you have specific needs. ****************************************** */trpgPrintBuffer::trpgPrintBuffer(){ curIndent = 0; indentStr[0] = 0;}// Increase the current indentvoid trpgPrintBuffer::IncreaseIndent(int amount){ curIndent+=amount; updateIndent();}// Decrease the current indentvoid trpgPrintBuffer::DecreaseIndent(int amount){ curIndent-=amount; curIndent = MAX(0,curIndent); updateIndent();}// Reprint the indent stringvoid trpgPrintBuffer::updateIndent(){ int i; for (i=0;i<MIN(199,curIndent);i++) indentStr[i] = ' '; indentStr[i] = 0;}// Constructors for File Print BuffertrpgFilePrintBuffer::trpgFilePrintBuffer(FILE *inFp){ isMine = false; fp = inFp; valid = true;}trpgFilePrintBuffer::trpgFilePrintBuffer(char *file){ isMine = true; fp = osgDB::fopen(file,"w"); valid = fp != NULL;}// Destructor for File Print BuffertrpgFilePrintBuffer::~trpgFilePrintBuffer(){ if (isMine && fp) fclose(fp); fp = NULL; valid = false;}// Print out a line of textbool trpgFilePrintBuffer::prnLine(const char *str){ if (!fp) return false; if (str) { fprintf(fp,indentStr); fprintf(fp,str); fprintf(fp,"\n"); } else fprintf(fp,"\n"); return true;}/* ************************************* Print Methods for TerraPage constructs All the print methods for every TerraPage object that is readable/writeable are here. These are used for debugging. ************************************* *//* Print out the header information. */bool trpgHeader::Print(trpgPrintBuffer &buf) const{ char ls[1024]; buf.prnLine("----Archive Header----"); buf.IncreaseIndent(); sprintf(ls,"verMinor = %d, verMajor = %d",verMinor,verMajor); buf.prnLine(ls); if((verMajor >= TRPG_NOMERGE_VERSION_MAJOR) && (verMinor >=TRPG_NOMERGE_VERSION_MINOR)) { sprintf(ls,"isMaster = %s, numRows = %d, numCols = %d",GetIsMaster()?"YES":"NO",rows,cols); buf.prnLine(ls); } sprintf(ls,"dbVerMinor = %d, dbVerMajor = %d",dbVerMinor,dbVerMajor); buf.prnLine(ls); sprintf(ls,"maxGroupID = %d",maxGroupID); buf.prnLine(ls); sprintf(ls,"sw = (%f,%f), ne = (%f,%f)",sw.x,sw.y,ne.x,ne.y); buf.prnLine(ls); sprintf(ls,"tileType = %d, origin = (%f,%f,%f)",tileType,origin.x,origin.y,origin.z); buf.prnLine(ls); sprintf(ls,"numLods = %d",numLods); buf.prnLine(ls); buf.IncreaseIndent(); for (int i=0;i<numLods;i++) { sprintf(ls,"tileSize = (%f,%f), lodSizes = (%d,%d), lodRanges = %f",tileSize[i].x,tileSize[i].y,lodSizes[i].x,lodSizes[i].y,lodRanges[i]); buf.prnLine(ls); } buf.DecreaseIndent(2); buf.prnLine(""); return true;}/* Print out texture environment information */bool trpgTextureEnv::Print(trpgPrintBuffer &buf) const{ char ls[1024]; buf.prnLine("----Texture Environment----"); buf.IncreaseIndent(); sprintf(ls,"envMode = %d",envMode); buf.prnLine(ls); sprintf(ls,"minFilter = %d, magFilter = %d",minFilter,magFilter); buf.prnLine(ls); sprintf(ls,"wrapS = %d, wrapT = %d",wrapS,wrapT); buf.prnLine(ls); buf.DecreaseIndent(); buf.prnLine(""); return true;}/* Print out the material information */bool trpgMaterial::Print(trpgPrintBuffer &buf) const{ char ls[1024]; buf.prnLine("----Material----"); buf.IncreaseIndent(); sprintf(ls,"isBumpMap = %d",(int)isBump); buf.prnLine(ls); sprintf(ls,"color = (%f,%f,%f)",color.red,color.green,color.blue); buf.prnLine(ls); sprintf(ls,"ambient = (%f,%f,%f)",ambient.red,ambient.green,ambient.blue); buf.prnLine(ls); sprintf(ls,"diffuse = (%f,%f,%f)",diffuse.red,diffuse.green,diffuse.blue); buf.prnLine(ls); sprintf(ls,"specular = (%f,%f,%f)",specular.red,specular.green,specular.blue); buf.prnLine(ls); sprintf(ls,"emission = (%f,%f,%f)",emission.red,emission.green,emission.blue); buf.prnLine(ls); sprintf(ls,"shininess = %f, shadeModel = %d",shininess,shadeModel); buf.prnLine(ls); sprintf(ls,"pointSize = %f, lineWidth = %f",pointSize,lineWidth); buf.prnLine(ls); sprintf(ls,"cullMode = %d, alphaFunc = %d",cullMode,alphaFunc); buf.prnLine(ls); sprintf(ls,"alpha = %f, alphaRef = %f",alpha,alphaRef); buf.prnLine(ls); sprintf(ls,"autoNormal = %d",autoNormal); buf.prnLine(ls); sprintf(ls,"fid = %d, smc = %d, stp = %d, swc = %d",attrSet.fid,attrSet.smc,attrSet.stp,attrSet.swc); buf.prnLine(ls); sprintf(ls,"numTile = %d",numTile); buf.prnLine(ls); sprintf(ls,"numTex = %d",numTex); buf.prnLine(ls); buf.IncreaseIndent(); for (int i=0;i<numTex;i++) { sprintf(ls,"texID[%d] = %d",i,texids[i]); buf.prnLine(ls); buf.IncreaseIndent(); texEnvs[i].Print(buf); buf.DecreaseIndent(); } buf.DecreaseIndent(2); buf.prnLine(); return true;}/* Print out the material tables. */bool trpgMatTable::Print(trpgPrintBuffer &buf) const{ char ls[1024]; buf.prnLine("----Material Table----"); buf.IncreaseIndent(); sprintf(ls,"numTable = %d",numTable); buf.prnLine(ls); sprintf(ls,"numMat = %d",numMat); buf.prnLine(ls); buf.IncreaseIndent(); MaterialMapType::const_iterator itr = materialMap.begin(); for ( ; itr != materialMap.end( ); itr++) { const trpgMaterial *mat; sprintf(ls,"Material %d",itr->first); buf.prnLine(ls); mat = (const_cast<trpgMatTable *>(this))->GetMaterialRef(0,itr->first); if(!mat) { sprintf(ls,"Error: Unable to load material!"); buf.prnLine(ls); } else mat->Print(buf); } buf.DecreaseIndent(2); return true;}/* Print out texture. */bool trpgTexture::Print(trpgPrintBuffer &buf) const{ char ls[1024]; buf.prnLine("----Texture----"); buf.IncreaseIndent(); sprintf(ls,"mode = %d, type = %d",mode,type); buf.prnLine(ls); sprintf(ls,"Name = %s",name); buf.prnLine(ls); sprintf(ls,"useCount = %d",useCount); buf.prnLine(ls); sprintf(ls,"sizeX = %d, sizeY = %d, sizeZ = %d",sizeX,sizeY,numLayer); buf.prnLine(ls);// sprintf(ls,"sensor band organization = %d",org); buf.prnLine(ls); // does this need to be added? sprintf(ls,"ismipmap = %d",isMipmap); buf.prnLine(ls); sprintf(ls,"addr.file = %d, addr.offset = %d",addr.file,addr.offset); buf.prnLine(ls); sprintf(ls,"addr.col = %d, addr.row = %d",addr.col,addr.row); buf.prnLine(ls); buf.DecreaseIndent(); buf.prnLine(); return true;}/* Print out texture table */bool trpgTexTable::Print(trpgPrintBuffer &buf) const{ char ls[1024]; buf.prnLine("----Texture Table----"); buf.IncreaseIndent(); TextureMapType::const_iterator itr = textureMap.begin(); for ( ; itr != textureMap.end( ); itr++) { sprintf(ls,"Texture %d",itr->first); buf.prnLine(ls); itr->second.Print(buf); } buf.DecreaseIndent(); buf.prnLine(); return true;}/* Print out model table */bool trpgModelTable::Print(trpgPrintBuffer &buf) const{ char ls[1024]; buf.prnLine("----Model Table----"); buf.IncreaseIndent(); ModelMapType::const_iterator itr = modelsMap.begin(); for ( ; itr != modelsMap.end( ); itr++) { sprintf(ls,"Model %d",itr->first); buf.prnLine(ls); itr->second.Print(buf); } buf.DecreaseIndent(); buf.prnLine(); return true;}/* Print out a model */bool trpgModel::Print(trpgPrintBuffer &buf) const{ char ls[1024]; buf.prnLine("----Model----"); buf.IncreaseIndent(); sprintf(ls,"type = %d",type); buf.prnLine(ls); if (name) { sprintf(ls,"name = %s",name); buf.prnLine(ls); } sprintf(ls,"diskRef = %d",(int)diskRef), buf.prnLine(ls); sprintf(ls,"useCount = %d",useCount); buf.prnLine(ls); buf.DecreaseIndent(); buf.prnLine(); return true;}/* Print out a tile header */bool trpgTileHeader::Print(trpgPrintBuffer &buf) const{ char ls[1024]; buf.prnLine("----Tile Header----"); buf.IncreaseIndent(); sprintf(ls,"matList size = %d",static_cast<int>(matList.size())); buf.prnLine(ls); buf.IncreaseIndent(); unsigned int i; for (i=0;i<matList.size();i++) { sprintf(ls,"matList[%d] = %d",i,matList[i]); buf.prnLine(ls); } buf.DecreaseIndent(); sprintf(ls,"modelList size = %d",static_cast<int>(modelList.size())); buf.prnLine(ls); buf.IncreaseIndent(); for (i=0;i<modelList.size();i++) { sprintf(ls,"modelList[%d] = %d",i,modelList[i]); buf.prnLine(ls); } buf.DecreaseIndent(); sprintf(ls,"local material list size = %d",static_cast<int>(locMats.size())); buf.prnLine(ls); buf.IncreaseIndent(); for (i=0;i<locMats.size();i++) locMats[i].Print(buf); buf.DecreaseIndent(); buf.DecreaseIndent(); buf.prnLine(); return true;}/* Print out color info */bool trpgColorInfo::Print(trpgPrintBuffer &buf) const{ char ls[1024];
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?