📄 tabmapobjectblock.cpp
字号:
WriteInt32(0); WriteInt32(0); // First/last coord block ref... will be written in CommitToFile() WriteInt32(0); WriteInt32(0); } if (UGKGetLastErrorNo() != 0) return -1; return 0;}/********************************************************************** * TABMAPObjectBlock::ReadCoord() * * Read the next pair of integer coordinates value from the block, and * apply the translation relative to to the center of the data block * if bCompressed=TRUE. * * This means that the returned coordinates are always absolute integer * coordinates, even when the source coords are in compressed form. * * Returns 0 if succesful or -1 if an error happened, in which case * UGKError() will have been called. **********************************************************************/int TABMAPObjectBlock::ReadIntCoord(UGKBool bCompressed, UGKInt32 &nX, UGKInt32 &nY){ if (bCompressed) //如果坐标是压缩的,X Y坐标只用了4字节 { nX = m_nCenterX + ReadInt16(); nY = m_nCenterY + ReadInt16(); } else //如果坐标没压缩,则X Y坐标需要8字节 { nX = ReadInt32(); nY = ReadInt32(); } if (UGKGetLastErrorNo() != 0) return -1; return 0;}/********************************************************************** * TABMAPObjectBlock::WriteIntCoord() * * Write a pair of integer coordinates values to the current position in the * the block. If bCompr=TRUE then the coordinates are written relative to * the object block center... otherwise they're written as 32 bits int. * * This function does not maintain the block's MBR and center... it is * assumed to have been set before the first call to WriteIntCoord() * * Returns 0 if succesful or -1 if an error happened, in which case * UGKError() will have been called. **********************************************************************/int TABMAPObjectBlock::WriteIntCoord(UGKInt32 nX, UGKInt32 nY, UGKBool bCompressed /*=FALSE*/){ /*----------------------------------------------------------------- * Write coords to the file. *----------------------------------------------------------------*/ if ((!bCompressed && (WriteInt32(nX) != 0 || WriteInt32(nY) != 0 ) ) || (bCompressed && (WriteInt16(nX - m_nCenterX) != 0 || WriteInt16(nY - m_nCenterY) != 0) ) ) { return -1; } return 0;}/********************************************************************** * TABMAPObjectBlock::WriteIntMBRCoord() * * Write 2 pairs of integer coordinates values to the current position * in the the block after making sure that min values are smaller than * max values. Use this function to write MBR coordinates for an object. * * If bCompr=TRUE then the coordinates are written relative to * the object block center... otherwise they're written as 32 bits int. * * This function does not maintain the block's MBR and center... it is * assumed to have been set before the first call to WriteIntCoord() * * Returns 0 if succesful or -1 if an error happened, in which case * UGKError() will have been called. **********************************************************************/int TABMAPObjectBlock::WriteIntMBRCoord(UGKInt32 nXMin, UGKInt32 nYMin, UGKInt32 nXMax, UGKInt32 nYMax, UGKBool bCompressed /*=FALSE*/){ if (WriteIntCoord(MIN(nXMin, nXMax), MIN(nYMin, nYMax), bCompressed) != 0 || WriteIntCoord(MAX(nXMin, nXMax), MAX(nYMin, nYMax), bCompressed) != 0 ) { return -1; } return 0;}/********************************************************************** * TABMAPObjectBlock::UpdateMBR() * * Update the block's MBR and center. * * Returns 0 if succesful or -1 if an error happened, in which case * UGKError() will have been called. **********************************************************************/int TABMAPObjectBlock::UpdateMBR(UGKInt32 nX, UGKInt32 nY){ if (nX < m_nMinX) m_nMinX = nX; if (nX > m_nMaxX) m_nMaxX = nX; if (nY < m_nMinY) m_nMinY = nY; if (nY > m_nMaxY) m_nMaxY = nY; m_nCenterX = (m_nMinX + m_nMaxX) /2; m_nCenterY = (m_nMinY + m_nMaxY) /2; return 0;}/********************************************************************** * TABMAPObjectBlock::AddCoordBlockRef() * * Update the first/last coord block fields in this object to contain * the specified block address. **********************************************************************/void TABMAPObjectBlock::AddCoordBlockRef(UGKInt32 nNewBlockAddress){ /*----------------------------------------------------------------- * Normally, new blocks are added to the end of the list, except * the first one which is the beginning and the end of the list at * the same time. *----------------------------------------------------------------*/ if (m_nFirstCoordBlock == 0) m_nFirstCoordBlock = nNewBlockAddress; m_nLastCoordBlock = nNewBlockAddress;}/********************************************************************** * TABMAPObjectBlock::GetMBR() * * Return the MBR for the current block. **********************************************************************/void TABMAPObjectBlock::GetMBR(UGKInt32 &nXMin, UGKInt32 &nYMin, UGKInt32 &nXMax, UGKInt32 &nYMax){ nXMin = m_nMinX; nYMin = m_nMinY; nXMax = m_nMaxX; nYMax = m_nMaxY; }/********************************************************************** * TABMAPObjectBlock::AddObject() * * Add an object to be eventually writtent to this object. The poObjHdr * becomes owned by the TABMAPObjectBlock object and will be destroyed * once we're done with it. * * In write mode, an array of TABMAPObjHdr objects is maintained in memory * until the object is full, at which time the block center is recomputed * and all objects are written to the block. **********************************************************************/int TABMAPObjectBlock::AddObject(TABMAPObjHdr *poObjHdr){ // We do not store NONE objects if (poObjHdr->m_nType == TAB_GEOM_NONE) { delete poObjHdr; return 0; } if (m_papoObjHdr == NULL || m_numObjects%10 == 0) { // Realloc the array... by steps of 10 m_papoObjHdr = (TABMAPObjHdr**)UGK_Realloc(m_papoObjHdr, (m_numObjects+10)* sizeof(TABMAPObjHdr*)); } m_papoObjHdr[m_numObjects++] = poObjHdr; // Maintain MBR of this object block. UpdateMBR(poObjHdr->m_nMinX, poObjHdr->m_nMinY); UpdateMBR(poObjHdr->m_nMaxX, poObjHdr->m_nMaxY); return 0;}/********************************************************************** * TABMAPObjectBlock::Dump() * * Dump block contents... available only in DEBUG mode. **********************************************************************/void TABMAPObjectBlock::Dump(FILE *fpOut, UGKBool bDetails){ if (fpOut == NULL) fpOut = stdout; fprintf(fpOut, "----- TABMAPObjectBlock::Dump() -----\n"); if (m_pabyBuf == NULL) { fprintf(fpOut, "Block has not been initialized yet."); } else { fprintf(fpOut,"Object Data Block (type %d) at offset %d.\n", m_nBlockType, m_nFileOffset); fprintf(fpOut," m_numDataBytes = %d\n", m_numDataBytes); fprintf(fpOut," m_nCenterX = %d\n", m_nCenterX); fprintf(fpOut," m_nCenterY = %d\n", m_nCenterY); fprintf(fpOut," m_nFirstCoordBlock = %d\n", m_nFirstCoordBlock); fprintf(fpOut," m_nLastCoordBlock = %d\n", m_nLastCoordBlock); } if (bDetails) { /* We need the mapfile's header block */ TABRawBinBlock *poBlock; TABMAPHeaderBlock *poHeader; poBlock = TABCreateMAPBlockFromFile(m_fp, 0, 512); if (poBlock==NULL || poBlock->GetBlockClass() != TABMAP_HEADER_BLOCK) { UGKError(ET_Failure, UGKErr_AssertionFailed, "Failed reading header block."); return; } poHeader = (TABMAPHeaderBlock *)poBlock; while(AdvanceToNextObject(poHeader) != -1) { fprintf(fpOut, " object id=%d, type=%d, offset=%d (%d), size=%d \n", m_nCurObjectId, m_nCurObjectType, m_nCurObjectOffset, m_nFileOffset + m_nCurObjectOffset, poHeader->GetMapObjectSize( m_nCurObjectType ) ); } delete poHeader; } fflush(fpOut);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -