📄 trpage_rarchive.cpp
字号:
blockx = x/denom; blocky = y/denom; sprintf(filename,"%s" PATHSEPERATOR "%d" PATHSEPERATOR "%d" PATHSEPERATOR "tile_%d_%d_%d.tpt", dir,blockx,blocky,x,y,lod); } else { sprintf(filename,"%s" PATHSEPERATOR "tile_%d_%d_%d.tpt",dir,x,y,lod); } // Open the file and read the contents FILE *fp= 0; try { if (!(fp = osgDB::fopen(filename,"rb"))) { throw 1; } // Find the file end if (fseek(fp,0,SEEK_END)) throw 1; // Note: This means tile is capped at 2 gigs long pos = ftell(fp); if (fseek(fp,0,SEEK_SET)) throw 1; // Now we know the size. Read the whole file buf.SetLength(pos); char *data = buf.GetDataPtr(); if (fread(data,pos,1,fp) != 1) throw 1; fclose(fp); fp = NULL; } catch (...) { if (fp) fclose(fp); return false; } return true;}bool trpgr_Archive::ReadTile(const trpgwAppAddress& addr, trpgMemReadBuffer &buf){ // Fetch the appendable file from the cache trpgrAppFile *tf = tileCache->GetFile(ness,addr.file,addr.col,addr.row); if (!tf) return false; // Fetch the tile if (!tf->Read(&buf,addr.offset)) return false; else return true;}// Get methodsconst trpgHeader *trpgr_Archive::GetHeader() const{ return &header;}const trpgMatTable *trpgr_Archive::GetMaterialTable() const{ return &materialTable;}trpgTexTable *trpgr_Archive::GetTexTable() { return &texTable;}const trpgModelTable *trpgr_Archive::GetModelTable() const{ return &modelTable;}const trpgTileTable *trpgr_Archive::GetTileTable() const{ return &tileTable;}const trpgLightTable *trpgr_Archive::GetLightTable() const{ return &lightTable;}const trpgRangeTable *trpgr_Archive::GetRangeTable() const{ return &rangeTable;}const trpgTextStyleTable *trpgr_Archive::GetTextStyleTable() const{ return &textStyleTable;}const trpgSupportStyleTable *trpgr_Archive::GetSupportStyleTable() const{ return &supportStyleTable;}const trpgLabelPropertyTable *trpgr_Archive::GetLabelPropertyTable() const{ return &labelPropertyTable;}trpgEndian trpgr_Archive::GetEndian() const{ return ness;}// Utility MBR routinebool trpgr_Archive::trpgGetTileMBR(uint32 x,uint32 y,uint32 lod,trpg3dPoint &ll,trpg3dPoint &ur) const{ if (!header.isValid()) return false; int32 numLod; header.GetNumLods(numLod); trpg2iPoint maxXY; header.GetLodSize(lod,maxXY); if (static_cast<int>(x) >= maxXY.x || static_cast<int>(y)>= maxXY.y) return false; trpg3dPoint origin; header.GetOrigin(origin); trpg2dPoint size; header.GetTileSize(lod,size); ll.x = origin.x + size.x*x; ll.y = origin.y + size.y*y; ur.x = origin.x + size.x*(x+1); ur.y = origin.y + size.y*(y+1); // If the tiles are local, we should have Z information trpgwAppAddress addr; float elev_min=0.0,elev_max=0.0; tileTable.GetTile(x,y,lod,addr,elev_min,elev_max); ll.z = elev_min; ur.z = elev_max; return true;}/* ***************** Read Image Helper ***************** */trpgrImageHelper::trpgrImageHelper(trpgEndian inNess,char *inDir, const trpgMatTable &inMatTable,const trpgTexTable &inTexTable,bool separateGeoTyp){ Init(inNess,inDir,inMatTable,inTexTable,separateGeoTyp);}void trpgrImageHelper::Init(trpgEndian inNess,char *inDir, const trpgMatTable &inMatTable,const trpgTexTable &inTexTable,bool separateGeoTyp){ ness = inNess; strcpy(dir,inDir); this->separateGeoTyp = separateGeoTyp; matTable = &inMatTable; texTable = &inTexTable; // Set up the texture cache // It doesn't do anything until it's called anyway char fullBase[1024]; sprintf(fullBase,"%s" PATHSEPERATOR "texFile",dir); texCache = GetNewRAppFileCache(fullBase,"txf"); if(separateGeoTyp) { sprintf(fullBase,"%s" PATHSEPERATOR "geotypFile",dir); geotypCache = GetNewRAppFileCache(fullBase,"txf"); } else { geotypCache = texCache; } }trpgrImageHelper::~trpgrImageHelper(){ if (texCache) { delete texCache; texCache = NULL; } if(separateGeoTyp && geotypCache) { delete geotypCache; geotypCache = NULL; }}trpgrAppFileCache* trpgrImageHelper::GetNewRAppFileCache(const char *fullBase,const char* /*ext*/){ return new trpgrAppFileCache(fullBase,"txf");}bool trpgrImageHelper::GetLocalGL(const trpgTexture *tex,char *data,int32 size){ // Make sure the texture is Local trpgTexture::ImageMode mode; tex->GetImageMode(mode); if (mode != trpgTexture::Local) return false; // Fetch data data trpgwAppAddress addr; tex->GetImageAddr(addr); trpgrAppFile *af = geotypCache->GetFile(ness,addr.file,addr.col,addr.row); if (!af) return false; if (!af->Read(data,addr.offset,0,size)) return false; return true;}bool trpgrImageHelper::GetMipLevelLocalGL(int miplevel, const trpgTexture *tex,char *data,int32 dataSize){ if ( miplevel >= tex->CalcNumMipmaps() || miplevel < 0 ) return false; // Make sure the texture is Local trpgTexture::ImageMode mode; tex->GetImageMode(mode); if (mode != trpgTexture::Local) return false; // Fetch data data trpgwAppAddress addr; tex->GetImageAddr(addr); trpgrAppFile *af = texCache->GetFile(ness,addr.file,addr.col,addr.row); if (!af) return false; int level_offset = (const_cast<trpgTexture*>(tex))->MipLevelOffset(miplevel); if (!af->Read(data,addr.offset,level_offset,dataSize)) return false; return true;}bool trpgrImageHelper::GetImageInfoForLocalMat(const trpgLocalMaterial *locMat, const trpgMaterial **retMat,const trpgTexture **retTex,int &totSize){ return GetNthImageInfoForLocalMat(locMat, 0, retMat, retTex, totSize);}bool trpgrImageHelper::GetNthImageInfoForLocalMat(const trpgLocalMaterial *locMat, int index, const trpgMaterial **retMat,const trpgTexture **retTex,int &totSize){ // Get the base material for the Local Material int32 matSubTable,matID; locMat->GetBaseMaterial(matSubTable,matID); // For right now, force the subtable number to match the index. // Eventually, either store multiple base materials for each local material, // or overhaul this in some other fashion. int numTables; if (!matTable->GetNumTable(numTables)) return false; if (index>=numTables) return false; if (index>0) matSubTable=index; // otherwise, leave it alone - could be nonzero const trpgMaterial *mat = matTable->GetMaterialRef(matSubTable,matID); if (!mat) return false; // Now get the texture (always the first one) trpgTextureEnv texEnv; int32 texID; if (!mat->GetTexture(0,texID,texEnv)) return false; const trpgTexture *tex = texTable->GetTextureRef(texID); if (!tex) return false; totSize = tex->CalcTotalSize(); *retTex = tex; *retMat = mat; return true;}bool trpgrImageHelper::GetImageForLocalMat(const trpgLocalMaterial *locMat,char *data,int dataSize){ return GetNthImageForLocalMat(locMat, 0, data, dataSize);}bool trpgrImageHelper::GetNthImageForLocalMat(const trpgLocalMaterial *locMat,int index, char *data,int dataSize){ if (!locMat->isValid()) return false; const trpgMaterial *mat; const trpgTexture *tex; int totSize; if (!GetNthImageInfoForLocalMat(locMat,index,&mat,&tex,totSize)) return false; // Determine the type trpgTexture::ImageMode imageMode; tex->GetImageMode(imageMode); switch (imageMode) { case trpgTexture::Template: { // Read the image data out of the Local image (in an archive somewhere) trpgwAppAddress addr; if (!locMat->GetNthAddr(index,addr)) return false; trpgrAppFile *af = texCache->GetFile(ness,addr.file,addr.col,addr.row); if (!af) return false; if (!af->Read(data,addr.offset,0,dataSize)) return false; } break; case trpgTexture::Global: // Note: Not dealing with Global textures yet return false; break; default: // This is not a valid Local Material return false; }; return true;}bool trpgrImageHelper::GetMipLevelForLocalMat(int miplevel, const trpgLocalMaterial *locMat,char *data,int dataSize){ return GetNthImageMipLevelForLocalMat(miplevel, locMat, 0, data, dataSize);}bool trpgrImageHelper::GetNthImageMipLevelForLocalMat(int miplevel, const trpgLocalMaterial *locMat, int index, char *data,int dataSize){ if (index>0) return false; // not yet, folks, if ever. index>1 means sensors for now. if (!locMat->isValid()) return false; const trpgMaterial *mat; const trpgTexture *tex; int totSize; if (!GetNthImageInfoForLocalMat(locMat,index,&mat,&tex,totSize)) return false; if ( miplevel >= tex->CalcNumMipmaps() || miplevel < 0 ) return false; // Determine the type trpgTexture::ImageMode imageMode; tex->GetImageMode(imageMode); switch (imageMode) { case trpgTexture::Template: { // Read the image data out of the Local image (in an archive somewhere) trpgwAppAddress addr; if (!locMat->GetNthAddr(index,addr)) return false; trpgrAppFile *af = texCache->GetFile(ness,addr.file,addr.col,addr.row); if (!af) return false; int level_offset = (const_cast<trpgTexture*>(tex))->MipLevelOffset(miplevel); if (!af->Read(data,addr.offset,level_offset,dataSize)) return false; } break; case trpgTexture::Global: // Note: Not dealing with Global textures yet return false; break; default: // This is not a valid Local Material return false; }; return true;}bool trpgrImageHelper::GetImagePath(const trpgTexture *tex,char *fullPath,int pathLen){ char name[1024]; int nameLen=1024; tex->GetName(name,nameLen); nameLen = strlen(name); if (static_cast<int>(strlen(dir)) + nameLen + 2 > pathLen) return false; sprintf(fullPath,"%s" PATHSEPERATOR "%s",dir,name); return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -