📄 dgnread.cpp
字号:
psDGN->abyElem + 0, anMin + 0, anMin + 1, anMin + 2, anMax + 0, anMax + 1, anMax + 2 ); else { CPLError(CE_Warning, CPLE_AppDefined, "DGNGetElementExtents() fails because the requested element\n" " does not have raw data available." ); return FALSE; } if( !bResult ) return FALSE;/* -------------------------------------------------------------------- *//* Transform to user coordinate system and return. The offset *//* is to convert from "binary offset" form to twos complement. *//* -------------------------------------------------------------------- */ psMin->x = anMin[0] - 2147483648.0; psMin->y = anMin[1] - 2147483648.0; psMin->z = anMin[2] - 2147483648.0; psMax->x = anMax[0] - 2147483648.0; psMax->y = anMax[1] - 2147483648.0; psMax->z = anMax[2] - 2147483648.0; DGNTransformPoint( psDGN, psMin ); DGNTransformPoint( psDGN, psMax ); return TRUE;}/************************************************************************//* DGNProcessElement() *//* *//* Assumes the raw element data has already been loaded, and *//* tries to convert it into an element structure. *//************************************************************************/static DGNElemCore *DGNProcessElement( DGNInfo *psDGN, int nType, int nLevel ){ DGNElemCore *psElement = NULL;/* -------------------------------------------------------------------- *//* Handle based on element type. *//* -------------------------------------------------------------------- */ switch( nType ) { case DGNT_CELL_HEADER: { DGNElemCellHeader *psCell; psCell = (DGNElemCellHeader *) CPLCalloc(sizeof(DGNElemCellHeader),1); psElement = (DGNElemCore *) psCell; psElement->stype = DGNST_CELL_HEADER; DGNParseCore( psDGN, psElement ); psCell->totlength = psDGN->abyElem[36] + psDGN->abyElem[37] * 256; DGNRad50ToAscii( psDGN->abyElem[38] + psDGN->abyElem[39] * 256, psCell->name + 0 ); DGNRad50ToAscii( psDGN->abyElem[40] + psDGN->abyElem[41] * 256, psCell->name + 3 ); psCell->cclass = psDGN->abyElem[42] + psDGN->abyElem[43] * 256; psCell->levels[0] = psDGN->abyElem[44] + psDGN->abyElem[45] * 256; psCell->levels[1] = psDGN->abyElem[46] + psDGN->abyElem[47] * 256; psCell->levels[2] = psDGN->abyElem[48] + psDGN->abyElem[49] * 256; psCell->levels[3] = psDGN->abyElem[50] + psDGN->abyElem[51] * 256; psCell->core.color = psDGN->abyElem[35]; if( psDGN->dimension == 2 ) { psCell->rnglow.x = DGN_INT32( psDGN->abyElem + 52 ); psCell->rnglow.y = DGN_INT32( psDGN->abyElem + 56 ); psCell->rnghigh.x = DGN_INT32( psDGN->abyElem + 60 ); psCell->rnghigh.y = DGN_INT32( psDGN->abyElem + 64 ); psCell->trans[0] = 1.0 * DGN_INT32( psDGN->abyElem + 68 ) / (1<<31); psCell->trans[1] = 1.0 * DGN_INT32( psDGN->abyElem + 72 ) / (1<<31); psCell->trans[2] = 1.0 * DGN_INT32( psDGN->abyElem + 76 ) / (1<<31); psCell->trans[3] = 1.0 * DGN_INT32( psDGN->abyElem + 80 ) / (1<<31); psCell->origin.x = DGN_INT32( psDGN->abyElem + 84 ); psCell->origin.y = DGN_INT32( psDGN->abyElem + 88 ); { double a, b, c, d, a2, c2; a = DGN_INT32( psDGN->abyElem + 68 ); b = DGN_INT32( psDGN->abyElem + 72 ); c = DGN_INT32( psDGN->abyElem + 76 ); d = DGN_INT32( psDGN->abyElem + 80 ); a2 = a * a; c2 = c * c; psCell->xscale = sqrt(a2 + c2) / 214748; psCell->yscale = sqrt(b*b + d*d) / 214748; if( (a2 + c2) <= 0.0 ) psCell->rotation = 0.0; else psCell->rotation = acos(a / sqrt(a2 + c2)); if (b <= 0) psCell->rotation = psCell->rotation * 180 / PI; else psCell->rotation = 360 - psCell->rotation * 180 / PI; } } else { psCell->rnglow.x = DGN_INT32( psDGN->abyElem + 52 ); psCell->rnglow.y = DGN_INT32( psDGN->abyElem + 56 ); psCell->rnglow.z = DGN_INT32( psDGN->abyElem + 60 ); psCell->rnghigh.x = DGN_INT32( psDGN->abyElem + 64 ); psCell->rnghigh.y = DGN_INT32( psDGN->abyElem + 68 ); psCell->rnghigh.z = DGN_INT32( psDGN->abyElem + 72 ); psCell->trans[0] = 1.0 * DGN_INT32( psDGN->abyElem + 76 ) / (1<<31); psCell->trans[1] = 1.0 * DGN_INT32( psDGN->abyElem + 80 ) / (1<<31); psCell->trans[2] = 1.0 * DGN_INT32( psDGN->abyElem + 84 ) / (1<<31); psCell->trans[3] = 1.0 * DGN_INT32( psDGN->abyElem + 88 ) / (1<<31); psCell->trans[4] = 1.0 * DGN_INT32( psDGN->abyElem + 92 ) / (1<<31); psCell->trans[5] = 1.0 * DGN_INT32( psDGN->abyElem + 96 ) / (1<<31); psCell->trans[6] = 1.0 * DGN_INT32( psDGN->abyElem + 100 ) / (1<<31); psCell->trans[7] = 1.0 * DGN_INT32( psDGN->abyElem + 104 ) / (1<<31); psCell->trans[8] = 1.0 * DGN_INT32( psDGN->abyElem + 108 ) / (1<<31); psCell->origin.x = DGN_INT32( psDGN->abyElem + 112 ); psCell->origin.y = DGN_INT32( psDGN->abyElem + 116 ); psCell->origin.z = DGN_INT32( psDGN->abyElem + 120 ); } DGNTransformPoint( psDGN, &(psCell->rnglow) ); DGNTransformPoint( psDGN, &(psCell->rnghigh) ); DGNTransformPoint( psDGN, &(psCell->origin) ); } break; case DGNT_CELL_LIBRARY: { DGNElemCellLibrary *psCell; int iWord; psCell = (DGNElemCellLibrary *) CPLCalloc(sizeof(DGNElemCellLibrary),1); psElement = (DGNElemCore *) psCell; psElement->stype = DGNST_CELL_LIBRARY; DGNParseCore( psDGN, psElement ); DGNRad50ToAscii( psDGN->abyElem[32] + psDGN->abyElem[33] * 256, psCell->name + 0 ); DGNRad50ToAscii( psDGN->abyElem[34] + psDGN->abyElem[35] * 256, psCell->name + 3 ); psElement->properties = psDGN->abyElem[38] + psDGN->abyElem[39] * 256; psCell->dispsymb = psDGN->abyElem[40] + psDGN->abyElem[41] * 256; psCell->cclass = psDGN->abyElem[42] + psDGN->abyElem[43] * 256; psCell->levels[0] = psDGN->abyElem[44] + psDGN->abyElem[45] * 256; psCell->levels[1] = psDGN->abyElem[46] + psDGN->abyElem[47] * 256; psCell->levels[2] = psDGN->abyElem[48] + psDGN->abyElem[49] * 256; psCell->levels[3] = psDGN->abyElem[50] + psDGN->abyElem[51] * 256; psCell->numwords = psDGN->abyElem[36] + psDGN->abyElem[37] * 256; memset( psCell->description, 0, sizeof(psCell->description) ); for( iWord = 0; iWord < 9; iWord++ ) { int iOffset = 52 + iWord * 2; DGNRad50ToAscii( psDGN->abyElem[iOffset] + psDGN->abyElem[iOffset+1] * 256, psCell->description + iWord * 3 ); } } break; case DGNT_LINE: { DGNElemMultiPoint *psLine; psLine = (DGNElemMultiPoint *) CPLCalloc(sizeof(DGNElemMultiPoint),1); psElement = (DGNElemCore *) psLine; psElement->stype = DGNST_MULTIPOINT; DGNParseCore( psDGN, psElement ); psLine->num_vertices = 2; if( psDGN->dimension == 2 ) { psLine->vertices[0].x = DGN_INT32( psDGN->abyElem + 36 ); psLine->vertices[0].y = DGN_INT32( psDGN->abyElem + 40 ); psLine->vertices[1].x = DGN_INT32( psDGN->abyElem + 44 ); psLine->vertices[1].y = DGN_INT32( psDGN->abyElem + 48 ); } else { psLine->vertices[0].x = DGN_INT32( psDGN->abyElem + 36 ); psLine->vertices[0].y = DGN_INT32( psDGN->abyElem + 40 ); psLine->vertices[0].z = DGN_INT32( psDGN->abyElem + 44 ); psLine->vertices[1].x = DGN_INT32( psDGN->abyElem + 48 ); psLine->vertices[1].y = DGN_INT32( psDGN->abyElem + 52 ); psLine->vertices[1].z = DGN_INT32( psDGN->abyElem + 56 ); } DGNTransformPoint( psDGN, psLine->vertices + 0 ); DGNTransformPoint( psDGN, psLine->vertices + 1 ); } break; case DGNT_LINE_STRING: case DGNT_SHAPE: case DGNT_CURVE: case DGNT_BSPLINE: { DGNElemMultiPoint *psLine; int i, count; int pntsize = psDGN->dimension * 4; count = psDGN->abyElem[36] + psDGN->abyElem[37]*256; psLine = (DGNElemMultiPoint *) CPLCalloc(sizeof(DGNElemMultiPoint)+(count-2)*sizeof(DGNPoint),1); psElement = (DGNElemCore *) psLine; psElement->stype = DGNST_MULTIPOINT; DGNParseCore( psDGN, psElement ); if( psDGN->nElemBytes < 38 + count * pntsize ) { CPLError( CE_Warning, CPLE_AppDefined, "Trimming multipoint vertices to %d from %d because\n" "element is short.\n", (psDGN->nElemBytes - 38) / pntsize, count ); count = (psDGN->nElemBytes - 38) / pntsize; } psLine->num_vertices = count; for( i = 0; i < psLine->num_vertices; i++ ) { psLine->vertices[i].x = DGN_INT32( psDGN->abyElem + 38 + i*pntsize ); psLine->vertices[i].y = DGN_INT32( psDGN->abyElem + 42 + i*pntsize ); if( psDGN->dimension == 3 ) psLine->vertices[i].z = DGN_INT32( psDGN->abyElem + 46 + i*pntsize ); DGNTransformPoint( psDGN, psLine->vertices + i ); } } break; case DGNT_GROUP_DATA: if( nLevel == DGN_GDL_COLOR_TABLE ) { psElement = DGNParseColorTable( psDGN ); } else { psElement = (DGNElemCore *) CPLCalloc(sizeof(DGNElemCore),1); psElement->stype = DGNST_CORE; DGNParseCore( psDGN, psElement ); } break; case DGNT_ELLIPSE: { DGNElemArc *psEllipse; psEllipse = (DGNElemArc *) CPLCalloc(sizeof(DGNElemArc),1); psElement = (DGNElemCore *) psEllipse; psElement->stype = DGNST_ARC; DGNParseCore( psDGN, psElement ); memcpy( &(psEllipse->primary_axis), psDGN->abyElem + 36, 8 ); DGN2IEEEDouble( &(psEllipse->primary_axis) ); psEllipse->primary_axis *= psDGN->scale; memcpy( &(psEllipse->secondary_axis), psDGN->abyElem + 44, 8 ); DGN2IEEEDouble( &(psEllipse->secondary_axis) ); psEllipse->secondary_axis *= psDGN->scale; if( psDGN->dimension == 2 ) { psEllipse->rotation = DGN_INT32( psDGN->abyElem + 52 ); psEllipse->rotation = psEllipse->rotation / 360000.0; memcpy( &(psEllipse->origin.x), psDGN->abyElem + 56, 8 ); DGN2IEEEDouble( &(psEllipse->origin.x) ); memcpy( &(psEllipse->origin.y), psDGN->abyElem + 64, 8 ); DGN2IEEEDouble( &(psEllipse->origin.y) ); } else { /* leave quaternion for later */ memcpy( &(psEllipse->origin.x), psDGN->abyElem + 68, 8 ); DGN2IEEEDouble( &(psEllipse->origin.x) ); memcpy( &(psEllipse->origin.y), psDGN->abyElem + 76, 8 ); DGN2IEEEDouble( &(psEllipse->origin.y) ); memcpy( &(psEllipse->origin.z), psDGN->abyElem + 84, 8 ); DGN2IEEEDouble( &(psEllipse->origin.z) ); psEllipse->quat[0] = DGN_INT32( psDGN->abyElem + 52 ); psEllipse->quat[1] = DGN_INT32( psDGN->abyElem + 56 ); psEllipse->quat[2] = DGN_INT32( psDGN->abyElem + 60 ); psEllipse->quat[3] = DGN_INT32( psDGN->abyElem + 64 ); } DGNTransformPoint( psDGN, &(psEllipse->origin) ); psEllipse->startang = 0.0; psEllipse->sweepang = 360.0; } break; case DGNT_ARC: { DGNElemArc *psEllipse; GInt32 nSweepVal; psEllipse = (DGNElemArc *) CPLCalloc(sizeof(DGNElemArc),1); psElement = (DGNElemCore *) psEllipse; psElement->stype = DGNST_ARC; DGNParseCore( psDGN, psElement ); psEllipse->startang = DGN_INT32( psDGN->abyElem + 36 ); psEllipse->startang = psEllipse->startang / 360000.0; if( psDGN->abyElem[41] & 0x80 ) { psDGN->abyElem[41] &= 0x7f; nSweepVal = -1 * DGN_INT32( psDGN->abyElem + 40 ); } else nSweepVal = DGN_INT32( psDGN->abyElem + 40 ); if( nSweepVal == 0 ) psEllipse->sweepang = 360.0; else psEllipse->sweepang = nSweepVal / 360000.0; memcpy( &(psEllipse->primary_axis), psDGN->abyElem + 44, 8 ); DGN2IEEEDouble( &(psEllipse->primary_axis) ); psEllipse->primary_axis *= psDGN->scale; memcpy( &(psEllipse->secondary_axis), psDGN->abyElem + 52, 8 ); DGN2IEEEDouble( &(psEllipse->secondary_axis) ); psEllipse->secondary_axis *= psDGN->scale;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -