⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dgnhelp.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 3 页
字号:
              DGNTagDef *psTagDef = psTagSet->tagList + iTag;              fprintf( fp, "    %d: name=%s, type=%d, prompt=%s",                        psTagDef->id, psTagDef->name, psTagDef->type,                        psTagDef->prompt );              if( psTagDef->type == 1 )                  fprintf( fp, ", default=%s\n",                            psTagDef->defaultValue.string );              else if( psTagDef->type == 3 || psTagDef->type == 5 )                  fprintf( fp, ", default=%d\n",                            psTagDef->defaultValue.integer );              else if( psTagDef->type == 4 )                  fprintf( fp, ", default=%g\n",                            psTagDef->defaultValue.real );              else                  fprintf( fp, ", default=<unknown>\n" );          }      }      break;      case DGNST_TAG_VALUE:      {          DGNElemTagValue *psTag = (DGNElemTagValue*) psElement;          fprintf( fp, "  tagType=%d, tagSet=%d, tagIndex=%d, tagLength=%d\n",                    psTag->tagType, psTag->tagSet, psTag->tagIndex,                    psTag->tagLength );          if( psTag->tagType == 1 )              fprintf( fp, "  value=%s\n", psTag->tagValue.string );          else if( psTag->tagType == 3 )              fprintf( fp, "  value=%d\n", psTag->tagValue.integer );          else if( psTag->tagType == 4 )              fprintf( fp, "  value=%g\n", psTag->tagValue.real );      }      break;      case DGNST_CONE:      {          DGNElemCone *psCone = (DGNElemCone *) psElement;          fprintf( fp,                    "  center_1=(%g,%g,%g) radius=%g\n"                   "  center_2=(%g,%g,%g) radius=%g\n"                   "  quat=%d,%d,%d,%d unknown=%d\n",                    psCone->center_1.x, psCone->center_1.y, psCone->center_1.z,                   psCone->radius_1,                    psCone->center_2.x, psCone->center_2.y, psCone->center_2.z,                   psCone->radius_2,                    psCone->quat[0], psCone->quat[1],                   psCone->quat[2], psCone->quat[3],                   psCone->unknown );      }      break;      default:        break;    }    if( psElement->attr_bytes > 0 )    {        int iLink;        fprintf( fp, "Attributes (%d bytes):\n", psElement->attr_bytes );                for( iLink = 0; TRUE; iLink++ )        {            int nLinkType, nEntityNum=0, nMSLink=0, nLinkSize, i;            unsigned char *pabyData;            pabyData = DGNGetLinkage( hDGN, psElement, iLink, &nLinkType,                                       &nEntityNum, &nMSLink, &nLinkSize );            if( pabyData == NULL )                break;            fprintf( fp, "Type=0x%04x", nLinkType );            if( nMSLink != 0 || nEntityNum != 0 )                fprintf( fp, ", EntityNum=%d, MSLink=%d",                          nEntityNum, nMSLink );            fprintf( fp, "\n  0x" );            for( i = 0; i < nLinkSize; i++ )                fprintf( fp, "%02x", pabyData[i] );            fprintf( fp, "\n" );                    }    }}/************************************************************************//*                           DGNTypeToName()                            *//************************************************************************//** * Convert type to name. * * Returns a human readable name for an element type such as DGNT_LINE. * * @param nType the DGNT_* type code to translate. * * @return a pointer to an internal string with the translation.  This string * should not be modified or freed. */const char *DGNTypeToName( int nType ){    static char szNumericResult[16];    switch( nType )    {      case DGNT_CELL_LIBRARY:        return "Cell Library";              case DGNT_CELL_HEADER:        return "Cell Header";              case DGNT_LINE:        return "Line";              case DGNT_LINE_STRING:        return "Line String";      case DGNT_GROUP_DATA:        return "Group Data";      case DGNT_SHAPE:        return "Shape";              case DGNT_TEXT_NODE:        return "Text Node";      case DGNT_DIGITIZER_SETUP:        return "Digitizer Setup";              case DGNT_TCB:        return "TCB";              case DGNT_LEVEL_SYMBOLOGY:        return "Level Symbology";              case DGNT_CURVE:        return "Curve";              case DGNT_COMPLEX_CHAIN_HEADER:        return "Complex Chain Header";              case DGNT_COMPLEX_SHAPE_HEADER:        return "Complex Shape Header";              case DGNT_ELLIPSE:        return "Ellipse";              case DGNT_ARC:        return "Arc";              case DGNT_TEXT:        return "Text";      case DGNT_BSPLINE:        return "B-Spline";      case DGNT_APPLICATION_ELEM:        return "Application Element";      case DGNT_SHARED_CELL_DEFN:        return "Shared Cell Definition";              case DGNT_SHARED_CELL_ELEM:        return "Shared Cell Element";              case DGNT_TAG_VALUE:        return "Tag Value";              case DGNT_CONE:        return "Cone";      case DGNT_3DSURFACE_HEADER:        return "3D Surface Header";      case DGNT_3DSOLID_HEADER:        return "3D Solid Header";      default:        sprintf( szNumericResult, "%d", nType );        return szNumericResult;    }}/************************************************************************//*                         DGNGetAttrLinkSize()                         *//************************************************************************//** * Get attribute linkage size.  * * Returns the size, in bytes, of the attribute linkage starting at byte * offset nOffset.  On failure a value of 0 is returned. * * @param hDGN the file from which the element originated. * @param psElement the element to report on. * @param nOffset byte offset within attribute data of linkage to check. * * @return size of linkage in bytes, or zero.  */int DGNGetAttrLinkSize( DGNHandle hDGN, DGNElemCore *psElement,                         int nOffset ){    if( psElement->attr_bytes < nOffset + 4 )        return 0;    /* DMRS Linkage */    if( (psElement->attr_data[nOffset+0] == 0          && psElement->attr_data[nOffset+1] == 0)        || (psElement->attr_data[nOffset+0] == 0             && psElement->attr_data[nOffset+1] == 0x80) )        return 8;    /* If low order bit of second byte is set, first byte is length */    if( psElement->attr_data[nOffset+1] & 0x10 )        return psElement->attr_data[nOffset+0] * 2 + 2;    /* unknown */    return 0;}/************************************************************************//*                           DGNGetLinkage()                            *//************************************************************************//** * Returns requested linkage raw data.  * * A pointer to the raw data for the requested attribute linkage is returned * as well as (potentially) various information about the linkage including * the linkage type, database entity number and MSLink value, and the length * of the raw linkage data in bytes. * * If the requested linkage (iIndex) does not exist a value of zero is  * returned. * * The entity number is (loosely speaking) the index of the table within * the current database to which the MSLINK value will refer.  The entity * number should be used to lookup the table name in the MSCATALOG table.  * The MSLINK value is the key value for the record in the target table.  * * @param hDGN the file from which the element originated. * @param psElement the element to report on. * @param iIndex the zero based index of the linkage to fetch. * @param pnLinkageType variable to return linkage type.  This may be one of * the predefined DGNLT_ values or a different value. This pointer may be NULL. * @param pnEntityNum variable to return the entity number in or NULL if not * required.   * @param pnMSLink variable to return the MSLINK value in, or NULL if not  * required. * @param pnLength variable to returned the linkage size in bytes or NULL. *  * @return pointer to raw internal linkage data.  This data should not be * altered or freed.  NULL returned on failure.  */unsigned char *DGNGetLinkage( DGNHandle hDGN, DGNElemCore *psElement,                               int iIndex, int *pnLinkageType,                              int *pnEntityNum, int *pnMSLink, int *pnLength )    {    int nAttrOffset;    int iLinkage, nLinkSize;    for( iLinkage=0, nAttrOffset=0;         (nLinkSize = DGNGetAttrLinkSize( hDGN, psElement, nAttrOffset)) != 0;         iLinkage++, nAttrOffset += nLinkSize )    {        if( iLinkage == iIndex )        {            int  nLinkageType=0, nEntityNum=0, nMSLink = 0;            CPLAssert( nLinkSize > 4 );            if( psElement->attr_data[nAttrOffset+0] == 0x00                && (psElement->attr_data[nAttrOffset+1] == 0x00                    || psElement->attr_data[nAttrOffset+1] == 0x80) )            {                nLinkageType = DGNLT_DMRS;                nEntityNum = psElement->attr_data[nAttrOffset+2]                     + psElement->attr_data[nAttrOffset+3] * 256;                nMSLink = psElement->attr_data[nAttrOffset+4]                     + psElement->attr_data[nAttrOffset+5] * 256                    + psElement->attr_data[nAttrOffset+6] * 65536;            }            else                nLinkageType = psElement->attr_data[nAttrOffset+2]                     + psElement->attr_data[nAttrOffset+3] * 256;            // Possibly an external database linkage?            if( nLinkSize == 16 && nLinkageType != DGNLT_SHAPE_FILL )            {                nEntityNum = psElement->attr_data[nAttrOffset+6]                     + psElement->attr_data[nAttrOffset+7] * 256;                nMSLink = psElement->attr_data[nAttrOffset+8]                     + psElement->attr_data[nAttrOffset+9] * 256                    + psElement->attr_data[nAttrOffset+10] * 65536                    + psElement->attr_data[nAttrOffset+11] * 65536 * 256;                            }            if( pnLinkageType != NULL )                *pnLinkageType = nLinkageType;            if( pnEntityNum != NULL )                *pnEntityNum = nEntityNum;            if( pnMSLink != NULL )                *pnMSLink = nMSLink;            if( pnLength != NULL )                *pnLength = nLinkSize;            return psElement->attr_data + nAttrOffset;        }    }                 return NULL;}/************************************************************************//*                         DGNRotationToQuat()                          *//*                                                                      *//*      Compute a quaternion for a given Z rotation.                    *//************************************************************************/void DGNRotationToQuaternion( double dfRotation, int *panQuaternion ){    double dfRadianRot = (dfRotation / 180.0)  * PI;    panQuaternion[0] = (int) (cos(-dfRadianRot/2.0) * 2147483647);    panQuaternion[1] = 0;    panQuaternion[2] = 0;    panQuaternion[3] = (int) (sin(-dfRadianRot/2.0) * 2147483647);}/************************************************************************//*                         DGNQuaternionToMatrix()                      *//*                                                                      *//*      Compute a rotation matrix for a given quaternion                *//* FIXME: Write documentation on how to use this matrix                 *//* (i.e. things like row/column major, OpenGL style or not)             *//* kintel 20030819                                                      *//************************************************************************/void DGNQuaternionToMatrix( int *quat, float *mat ){  double q[4];  for (int i=0;i<4;i++) q[i] = 1.0 * quat[i] / (1<<31);  mat[0*3+0] = (float) (q[0]*q[0] - q[1]*q[1] - q[2]*q[2] + q[3]*q[3]);  mat[0*3+1] = (float) (2 * (q[2]*q[3] + q[0]*q[1]));  mat[0*3+2] = (float) (2 * (q[0]*q[2] - q[1]*q[3]));  mat[1*3+0] = (float) (2 * (q[0]*q[1] - q[2]*q[3]));  mat[1*3+1] = (float) (-q[0]*q[0] + q[1]*q[1] - q[2]*q[2] + q[3]*q[3]);  mat[1*3+2] = (float) (2 * (q[0]*q[3] + q[1]*q[2]));  mat[2*3+0] = (float) (2 * (q[0]*q[2] + q[1]*q[3]));   mat[2*3+1] = (float) (2 * (q[1]*q[2] - q[0]*q[3]));  mat[2*3+2] = (float) (-q[0]*q[0] - q[1]*q[1] + q[2]*q[2] + q[3]*q[3]);}/************************************************************************//*                  DGNTransformPointWithQuaternion()                   *//************************************************************************/void DGNTransformPointWithQuaternionVertex( int *quat, DGNPoint *v1, DGNPoint *v2 ){/* ==================================================================== *//*      Original code provided by kintel 20030819, but assumed to be    *//*      incomplete.                                                     *//* ==================================================================== */#ifdef notdef    See below for sketched implementation. kintel 20030819.                               float x,y,z,w;    // FIXME: Convert quat to x,y,z,w    v2.x = w*w*v1.x + 2*y*w*v1.z - 2*z*w*v1.y + x*x*v1.x + 2*y*x*v1.y + 2*z*x*v1.z - z*z*v1.x - y*y*v1.x;     v2.y = 2*x*y*v1.x + y*y*v1.y + 2*z*y*v1.z + 2*w*z*v1.x - z*z*v1.y + w*w*v1.y - 2*x*w*v1.z - x*x*v1.y;     v2.z = 2*x*z*v1.x + 2*y*z*v1.y + z*z*v1.z - 2*w*y*v1.x - y*y*v1.z + 2*w*x*v1.y - x*x*v1.z + w*w*v1.z;#endif/* ==================================================================== *//*      Impelementation provided by Peggy Jung - 2004/03/05.            *//*      peggy.jung at moskito-gis dot de.  I haven't tested it.         *//* ==================================================================== *//*  Version: 0.1                                 Datum: 26.01.2004 IN:x,y,z               // DGNPoint &v1quat[]              //  OUT:newX, newY, newZ    // DGNPoint &v2A u t o r  :  Peggy Jung*//*    double ROT[12];  //rotation matrix for a given quaternion    double xx, xy, xz, xw, yy, yz, yw, zz, zw;    double a, b, c, d, n, x, y, z;    x = v1->x;    y = v1->y;    z = v1->z;     n = sqrt((double)PDP2PC_long(quat[0])*(double)PDP2PC_long(quat[0])+(double)PDP2PC_long(quat[1])*(double)PDP2PC_long(quat[1])+             (double)PDP2PC_long(quat[2])*(double)PDP2PC_long(quat[2])+(double)PDP2PC_long(quat[3])*(double)PDP2PC_long(quat[3]));     a = (double)PDP2PC_long(quat[0])/n; //w    b = (double)PDP2PC_long(quat[1])/n; //x    c = (double)PDP2PC_long(quat[2])/n; //y    d = (double)PDP2PC_long(quat[3])/n; //z     xx      = b*b;    xy      = b*c;    xz      = b*d;    xw      = b*a;     yy      = c*c;    yz      = c*d;    yw      = c*a;     zz      = d*d;    zw      = d+a;     ROT[0] = 1 - 2 * yy - 2 * zz ;    ROT[1] =     2 * xy - 2 * zw ;    ROT[2] =     2 * xz + 2 * yw ;     ROT[4] =     2 * xy + 2 * zw ;    ROT[5] = 1 - 2 * xx - 2 * zz ;    ROT[6] =     2 * yz - 2 * xw ;     ROT[8] =     2 * xz - 2 * yw ;    ROT[9] =     2 * yz + 2 * xw ;    ROT[10] = 1 - 2 * xx - 2 * yy ;     v2->x = ROT[0]*x + ROT[1]*y + ROT[2]*z;    v2->y = ROT[4]*x + ROT[5]*y + ROT[6]*z;    v2->z = ROT[8]*x + ROT[9]*y + ROT[10]*z;*/}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -