Exemple #1
0
    void DiMeshSerializerImpl::WriteSubMesh( DiSubMesh* pMesh )
    {
        WriteChunkHeader(DI_SUBMESH, CalcSubMeshSize(pMesh));

        WriteString(pMesh->GetMaterialName());

        unsigned int indexCount = pMesh->GetIndexNum();
        WriteInts(&indexCount,1);

        bool u32 = pMesh->GetIndexSize() == 32;
        WriteBools(&u32,1);

        uint16 primitive = (uint16)pMesh->GetPrimitiveType();
        WriteShorts(&primitive,1);

        WriteData(pMesh->GetIndexData(),
            (pMesh->GetIndexSize() / 8) * pMesh->GetIndexNum(), 1);

        WriteGeometry(pMesh);

        if (!pMesh->mBoneWeights.empty())
        {
            WriteSubMeshBoneWeights(pMesh);
        }
    }
HRESULT CXMLExporter::WriteModel()
{
    try
    {
        if (m_pProgressBar)
        {
            m_pProgressBar->SetPercentDone(0.0);
            m_pProgressBar->SetProgressMessage(LoadLocalizedString(IDS_WRITING_TEXTURE_FILES));
        }
        WriteTextureFiles();

        Write("<SkpToXML xmlversion=\"1.0\" skpversion=\"5.0\" units=\"inches\">\n");

        if (m_pProgressBar)
        {
            m_pProgressBar->SetPercentDone(10.0);
            m_pProgressBar->SetProgressMessage(LoadLocalizedString(IDS_WRITING_LAYERS));
        }
        WriteLayers();

        if (m_pProgressBar)
        {
            m_pProgressBar->SetPercentDone(20.0);
            m_pProgressBar->SetProgressMessage(LoadLocalizedString(IDS_WRITING_MATERIALS));
        }
        WriteMaterials();

        if (m_pProgressBar)
        {
            m_pProgressBar->SetPercentDone(30.0);
            m_pProgressBar->SetProgressMessage(LoadLocalizedString(IDS_WRITING_OPTIONS));
        }
        WriteOptions();

        if (m_pProgressBar)
        {
            m_pProgressBar->SetPercentDone(40.0);
            m_pProgressBar->SetProgressMessage(LoadLocalizedString(IDS_WRITING_GEOMETRY));
        }
        WriteGeometry();

        Write("</SkpToXML>");

        if (m_pProgressBar)
        {
            m_pProgressBar->SetPercentDone(100.0);
            m_pProgressBar->SetProgressMessage(LoadLocalizedString(IDS_EXPORT_COMPLETE));
        }

        return S_OK;
    }
    catch(HRESULT hr)
    {
        return hr;
    }
}
Exemple #3
0
void FgfUtil::WriteGeometry(FdoIGeometry* geometry, FdoByteArray ** outputStream)
{
    FdoInt32 dimensionality = 0;
    FdoInt32 numPositions = 0;
    FdoInt32 numOrdsPerPos = 0;
    FdoInt32 numOrds = 0;
    const double * ordinates = NULL;
    FdoInt32 numRings = 0;
    FdoInt32 numSubGeometries = 0;
    FdoInt32 numCurveSegments = 0;
    FdoPtr<FdoIRing> ring;
    FdoPtr<FdoILinearRing> lRing;
    FdoPtr<FdoIDirectPosition> pos;
    FdoILineString * ls;
    FdoIPoint * pt;
    FdoIPolygon * poly;
    FdoIMultiPoint * mpt;
    FdoIMultiLineString * mls;
    FdoIMultiPolygon * mpoly;
    FdoICurveString * cs;
    FdoIMultiCurveString * mcs;
    FdoICurvePolygon * cpoly;
    FdoIMultiCurvePolygon * mcpoly;
    FdoIMultiGeometry * mgeom;
    FdoInt32 i;

    FdoGeometryType geometryType = geometry->GetDerivedType();
    FGFUTIL_WRITE_INT32(outputStream, geometryType);

    switch (geometryType)
    {
	case FdoGeometryType_LineString:
        ls = static_cast<FdoILineString *>(geometry);
	    dimensionality = ls->GetDimensionality();
	    numPositions = ls->GetCount();
	    FGFUTIL_WRITE_INT32(outputStream, dimensionality);
	    FGFUTIL_WRITE_INT32(outputStream, numPositions);
        numOrdsPerPos = GeometryUtility::DimensionalityToNumOrdinates(dimensionality);
        numOrds = numPositions * numOrdsPerPos;
        ordinates = ls->GetOrdinates();
        FGFUTIL_WRITE_DOUBLES(outputStream, numOrds, ordinates);
		break;

	case FdoGeometryType_Point:
        pt = static_cast<FdoIPoint *>(geometry);
        dimensionality = pt->GetDimensionality();
	    numPositions = 1;
	    FGFUTIL_WRITE_INT32(outputStream, dimensionality);
        numOrdsPerPos = GeometryUtility::DimensionalityToNumOrdinates(dimensionality);
        numOrds = numPositions * numOrdsPerPos;
        ordinates = pt->GetOrdinates();
        FGFUTIL_WRITE_DOUBLES(outputStream, numOrds, ordinates);
		break;

	case FdoGeometryType_Polygon:
        poly = static_cast<FdoIPolygon *>(geometry);
	    dimensionality = poly->GetDimensionality();
	    FGFUTIL_WRITE_INT32(outputStream, dimensionality);
	    numRings = poly->GetInteriorRingCount();
	    FGFUTIL_WRITE_INT32(outputStream, numRings+1);			// Include exterior ring in count
	    lRing = poly->GetExteriorRing();
	    FgfUtil::WriteLinearRing(lRing, outputStream);
	    for (i=0; i<numRings; i++)
	    {
		    lRing = poly->GetInteriorRing(i);
		    FgfUtil::WriteLinearRing(lRing, outputStream);
	    }
		break;

	case FdoGeometryType_MultiPoint:
        mpt = static_cast<FdoIMultiPoint *>(geometry);
	    numSubGeometries = mpt->GetCount();
	    FGFUTIL_WRITE_INT32(outputStream, numSubGeometries);
	    for (i=0; i<numSubGeometries; i++)
	    {
		    FdoPtr<FdoIPoint> pnt = mpt->GetItem(i);
            WriteGeometry(pnt, outputStream);
	    }
		break;

	case FdoGeometryType_MultiLineString:
        mls = static_cast<FdoIMultiLineString *>(geometry);
	    numSubGeometries = mls->GetCount();
	    FGFUTIL_WRITE_INT32(outputStream, numSubGeometries);
	    for (i=0; i<numSubGeometries; i++)
        {
            FdoPtr<FdoILineString> lineString = mls->GetItem(i);
            WriteGeometry(lineString, outputStream);
        }
		break;

	case FdoGeometryType_MultiPolygon:
        mpoly = static_cast<FdoIMultiPolygon *>(geometry);
	    numSubGeometries = mpoly->GetCount(); 
	    FGFUTIL_WRITE_INT32(outputStream, numSubGeometries);
	    for (i=0; i<numSubGeometries; i++)
        {
            FdoPtr<FdoIPolygon> polygon = mpoly->GetItem(i);
            WriteGeometry(polygon, outputStream);
        }
		break;

	case FdoGeometryType_CurveString:
        cs = static_cast<FdoICurveString *>(geometry);
	    dimensionality = cs->GetDimensionality();
	    FGFUTIL_WRITE_INT32(outputStream, dimensionality);
	    pos = cs->GetStartPosition();
	    WriteDirectPosition(outputStream, pos);
	    numCurveSegments = cs->GetCount();
	    FGFUTIL_WRITE_INT32(outputStream, numCurveSegments);
	    for (i=0; i<numCurveSegments; i++)
	    {
		    FdoPtr<FdoICurveSegmentAbstract> curveSeg = cs->GetItem(i);
		    WriteCurveSegment(curveSeg, outputStream);
	    }
		break;

	case FdoGeometryType_MultiCurveString:
        mcs = static_cast<FdoIMultiCurveString *>(geometry);
	    numSubGeometries = mcs->GetCount();
	    FGFUTIL_WRITE_INT32(outputStream, numSubGeometries);
	    for (i=0; i<numSubGeometries; i++)
	    {
		    FdoPtr<FdoICurveString> curveString = mcs->GetItem(i);
            WriteGeometry(curveString, outputStream);
	    }
		break;

	case FdoGeometryType_CurvePolygon:
        cpoly = static_cast<FdoICurvePolygon *>(geometry);
	    dimensionality = cpoly->GetDimensionality();
	    FGFUTIL_WRITE_INT32(outputStream, dimensionality);
	    numRings = cpoly->GetInteriorRingCount();
	    FGFUTIL_WRITE_INT32(outputStream, numRings + 1);			// Include exterior ring
	    ring = cpoly->GetExteriorRing();
	    FgfUtil::WriteRing(ring, outputStream);

	    // Interior rings
	    for (i=0; i<numRings; i++)
	    {
		    ring = cpoly->GetInteriorRing(i);
		    FgfUtil::WriteRing(ring, outputStream);
	    }
		break;

	case FdoGeometryType_MultiCurvePolygon:
        mcpoly = static_cast<FdoIMultiCurvePolygon *>(geometry);
	    numSubGeometries = mcpoly->GetCount();
	    FGFUTIL_WRITE_INT32(outputStream, numSubGeometries);
	    for (i=0; i<numSubGeometries; i++)
	    {
		    FdoPtr<FdoICurvePolygon> curvePolygon = mcpoly->GetItem(i);
            WriteGeometry(curvePolygon, outputStream);
	    }
		break;

	case FdoGeometryType_MultiGeometry:
        mgeom = static_cast<FdoIMultiGeometry *>(geometry);
	    numSubGeometries = mgeom->GetCount(); 
	    FGFUTIL_WRITE_INT32(outputStream, numSubGeometries);
	    for (i=0; i<numSubGeometries; i++)
	    {
            FdoPtr<FdoIGeometry> geom = mgeom->GetItem(i);
            WriteGeometry(geom, outputStream);
	    }
		break;

    default:
    	throw FdoException::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_1_UNKNOWN_GEOMETRY_TYPE), 
                                                               L"FgfUtil::WriteGeometry",
                                                               geometryType));
    }
}
int S57Writer::WritePrimitive( OGRFeature *poFeature )

{
    DDFRecord *poRec = MakeRecord();
    DDFField *poField;
    OGRGeometry *poGeom = poFeature->GetGeometryRef();

/* -------------------------------------------------------------------- */
/*      Add the VRID field.                                             */
/* -------------------------------------------------------------------- */

    poField = poRec->AddField( poModule->FindFieldDefn( "VRID" ) );

    poRec->SetIntSubfield   ( "VRID", 0, "RCNM", 0, 
                              poFeature->GetFieldAsInteger( "RCNM") );
    poRec->SetIntSubfield   ( "VRID", 0, "RCID", 0, 
                              poFeature->GetFieldAsInteger( "RCID") );
    poRec->SetIntSubfield   ( "VRID", 0, "RVER", 0, 1 );
    poRec->SetIntSubfield   ( "VRID", 0, "RUIN", 0, 1 );

/* -------------------------------------------------------------------- */
/*      Handle simple point.                                            */
/* -------------------------------------------------------------------- */
    if( poGeom != NULL && wkbFlatten(poGeom->getGeometryType()) == wkbPoint )
    {
        double dfX, dfY, dfZ;
        OGRPoint *poPoint = (OGRPoint *) poGeom;

        CPLAssert( poFeature->GetFieldAsInteger( "RCNM") == RCNM_VI 
                   || poFeature->GetFieldAsInteger( "RCNM") == RCNM_VC ); 

        dfX = poPoint->getX();
        dfY = poPoint->getY();
        dfZ = poPoint->getZ();
        
        if( dfZ == 0.0 )
            WriteGeometry( poRec, 1, &dfX, &dfY, NULL );
        else
            WriteGeometry( poRec, 1, &dfX, &dfY, &dfZ );
    }

/* -------------------------------------------------------------------- */
/*      For multipoints we assuming SOUNDG, and write out as SG3D.      */
/* -------------------------------------------------------------------- */
    else if( poGeom != NULL 
             && wkbFlatten(poGeom->getGeometryType()) == wkbMultiPoint )
    {
        OGRMultiPoint *poMP = (OGRMultiPoint *) poGeom;
        int i, nVCount = poMP->getNumGeometries();
        double *padfX, *padfY, *padfZ;

        CPLAssert( poFeature->GetFieldAsInteger( "RCNM") == RCNM_VI 
                   || poFeature->GetFieldAsInteger( "RCNM") == RCNM_VC ); 

        padfX = (double *) CPLMalloc(sizeof(double) * nVCount);
        padfY = (double *) CPLMalloc(sizeof(double) * nVCount);
        padfZ = (double *) CPLMalloc(sizeof(double) * nVCount);

        for( i = 0; i < nVCount; i++ )
        {
            OGRPoint *poPoint = (OGRPoint *) poMP->getGeometryRef( i );
            padfX[i] = poPoint->getX();
            padfY[i] = poPoint->getY();
            padfZ[i] = poPoint->getZ();
        }

        WriteGeometry( poRec, nVCount, padfX, padfY, padfZ );

        CPLFree( padfX );
        CPLFree( padfY );
        CPLFree( padfZ );
    }

/* -------------------------------------------------------------------- */
/*      Handle LINESTRINGs (edge) geometry.                             */
/* -------------------------------------------------------------------- */
    else if( poGeom != NULL 
             && wkbFlatten(poGeom->getGeometryType()) == wkbLineString )
    {
        OGRLineString *poLS = (OGRLineString *) poGeom;
        int i, nVCount = poLS->getNumPoints();
        double *padfX, *padfY;

        CPLAssert( poFeature->GetFieldAsInteger( "RCNM") == RCNM_VE );

        padfX = (double *) CPLMalloc(sizeof(double) * nVCount);
        padfY = (double *) CPLMalloc(sizeof(double) * nVCount);

        for( i = 0; i < nVCount; i++ )
        {
            padfX[i] = poLS->getX(i);
            padfY[i] = poLS->getY(i);
        }

        WriteGeometry( poRec, nVCount, padfX, padfY, NULL );

        CPLFree( padfX );
        CPLFree( padfY );
        
    }

/* -------------------------------------------------------------------- */
/*      edge node linkages.                                             */
/* -------------------------------------------------------------------- */
    if( poFeature->GetDefnRef()->GetFieldIndex( "NAME_RCNM_0" ) >= 0 )
    {
        DDFField *poField;
        char     szName[5];
        int      nRCID;

        CPLAssert( poFeature->GetFieldAsInteger( "NAME_RCNM_0") == RCNM_VC );

        poField = poRec->AddField( poModule->FindFieldDefn( "VRPT" ) );
        
        nRCID = poFeature->GetFieldAsInteger( "NAME_RCID_0");
        szName[0] = RCNM_VC;
        szName[1] = nRCID & 0xff;
        szName[2] = (nRCID & 0xff00) >> 8;
        szName[3] = (nRCID & 0xff0000) >> 16;
        szName[4] = (nRCID & 0xff000000) >> 24;
        
        poRec->SetStringSubfield( "VRPT", 0, "NAME", 0, szName, 5 );
        poRec->SetIntSubfield   ( "VRPT", 0, "ORNT", 0, 
                                  poFeature->GetFieldAsInteger( "ORNT_0") );
        poRec->SetIntSubfield   ( "VRPT", 0, "USAG", 0, 
                                  poFeature->GetFieldAsInteger( "USAG_0") );
        poRec->SetIntSubfield   ( "VRPT", 0, "TOPI", 0, 
                                  poFeature->GetFieldAsInteger( "TOPI_0") );
        poRec->SetIntSubfield   ( "VRPT", 0, "MASK", 0, 
                                  poFeature->GetFieldAsInteger( "MASK_0") );
        
        nRCID = poFeature->GetFieldAsInteger( "NAME_RCID_1");
        szName[0] = RCNM_VC;
        szName[1] = nRCID & 0xff;
        szName[2] = (nRCID & 0xff00) >> 8;
        szName[3] = (nRCID & 0xff0000) >> 16;
        szName[4] = (nRCID & 0xff000000) >> 24;

        poRec->SetStringSubfield( "VRPT", 0, "NAME", 1, szName, 5 );
        poRec->SetIntSubfield   ( "VRPT", 0, "ORNT", 1, 
                                  poFeature->GetFieldAsInteger( "ORNT_1") );
        poRec->SetIntSubfield   ( "VRPT", 0, "USAG", 1, 
                                  poFeature->GetFieldAsInteger( "USAG_1") );
        poRec->SetIntSubfield   ( "VRPT", 0, "TOPI", 1, 
                                  poFeature->GetFieldAsInteger( "TOPI_1") );
        poRec->SetIntSubfield   ( "VRPT", 0, "MASK", 1, 
                                  poFeature->GetFieldAsInteger( "MASK_1") );
    }
Exemple #5
0
OGRErr OGRGmtLayer::WriteGeometry( OGRGeometryH hGeom, int bHaveAngle )

{
/* -------------------------------------------------------------------- */
/*      This is a geometry with sub-geometries.                         */
/* -------------------------------------------------------------------- */
    if( OGR_G_GetGeometryCount( hGeom ) > 0 )
    {
        OGRErr eErr = OGRERR_NONE;

        for( int iGeom = 0;
             iGeom < OGR_G_GetGeometryCount(hGeom) && eErr == OGRERR_NONE;
             iGeom++ )
        {
            // We need to emit polygon @P and @H items while we still
            // know this is a polygon and which is the outer and inner
            // ring.
            if( wkbFlatten(OGR_G_GetGeometryType(hGeom)) == wkbPolygon )
            {
                if( !bHaveAngle )
                {
                    VSIFPrintfL( fp, ">\n" );
                    bHaveAngle = TRUE;
                }
                if( iGeom == 0 )
                    VSIFPrintfL( fp, "# @P\n" );
                else
                    VSIFPrintfL( fp, "# @H\n" );
            }

            eErr = WriteGeometry( OGR_G_GetGeometryRef( hGeom, iGeom ),
                                  bHaveAngle );
            bHaveAngle = FALSE;
        }
        return eErr;
    }

/* -------------------------------------------------------------------- */
/*      If this is not a point we need to have an angle bracket to      */
/*      mark the vertex list.                                           */
/* -------------------------------------------------------------------- */
    if( wkbFlatten(OGR_G_GetGeometryType(hGeom)) != wkbPoint
        && !bHaveAngle )
        VSIFPrintfL( fp, ">\n" );

/* -------------------------------------------------------------------- */
/*      Dump vertices.                                                  */
/* -------------------------------------------------------------------- */
    const int nPointCount = OGR_G_GetPointCount(hGeom);
    const int nDim = OGR_G_GetCoordinateDimension(hGeom);
    // For testing only. Ticket #6453
    const bool bUseTab = CPLTestBool( CPLGetConfigOption("GMT_USE_TAB", "FALSE") );

    for( int iPoint = 0; iPoint < nPointCount; iPoint++ )
    {
        const double dfX = OGR_G_GetX( hGeom, iPoint );
        const double dfY = OGR_G_GetY( hGeom, iPoint );
        const double dfZ = OGR_G_GetZ( hGeom, iPoint );

        sRegion.Merge( dfX, dfY );
        char szLine[128];
        OGRMakeWktCoordinate( szLine, dfX, dfY, dfZ, nDim );
        if( bUseTab )
        {
            for( char* szPtr = szLine; *szPtr != '\0'; ++szPtr )
            {
                if( *szPtr == ' ' )
                    *szPtr = '\t';
            }
        }
        if( VSIFPrintfL( fp, "%s\n", szLine ) < 1 )
        {
            CPLError( CE_Failure, CPLE_FileIO,
                      "Gmt write failure: %s",
                      VSIStrerror( errno ) );
            return OGRERR_FAILURE;
        }
    }

    return OGRERR_NONE;
}
Exemple #6
0
OGRErr OGRGmtLayer::ICreateFeature( OGRFeature *poFeature )

{
    if( !bUpdate )
    {
        CPLError( CE_Failure, CPLE_NoWriteAccess,
                  "Cannot create features on read-only dataset." );
        return OGRERR_FAILURE;
    }

/* -------------------------------------------------------------------- */
/*      Do we need to write the header describing the fields?           */
/* -------------------------------------------------------------------- */
    if( !bHeaderComplete )
    {
        OGRErr eErr = CompleteHeader( poFeature->GetGeometryRef() );

        if( eErr != OGRERR_NONE )
            return eErr;
    }

/* -------------------------------------------------------------------- */
/*      Write out the feature                                           */
/* -------------------------------------------------------------------- */
    OGRGeometry *poGeom = poFeature->GetGeometryRef();

    if( poGeom == NULL )
    {
        CPLError( CE_Failure, CPLE_AppDefined,
                  "Features without geometry not supported by GMT writer." );
        return OGRERR_FAILURE;
    }

    if( poFeatureDefn->GetGeomType() == wkbUnknown )
        poFeatureDefn->SetGeomType(wkbFlatten(poGeom->getGeometryType()));

    // Do we need a vertex collection marker grouping vertices.
    if( poFeatureDefn->GetGeomType() != wkbPoint )
        VSIFPrintfL( fp, ">\n" );

/* -------------------------------------------------------------------- */
/*      Write feature properties()                                      */
/* -------------------------------------------------------------------- */
    if( poFeatureDefn->GetFieldCount() > 0 )
    {
        CPLString osFieldData;

        for( int iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
        {
            OGRFieldType eFType=poFeatureDefn->GetFieldDefn(iField)->GetType();
            const char *pszRawValue = poFeature->GetFieldAsString(iField);

            if( iField > 0 )
                osFieldData += "|";

            // We do not want prefix spaces for numeric values.
            if( eFType == OFTInteger || eFType == OFTReal )
                while( *pszRawValue == ' ' )
                    pszRawValue++;

            if( strchr(pszRawValue,' ') || strchr(pszRawValue,'|')
                || strchr(pszRawValue, '\t') || strchr(pszRawValue, '\n') )
            {
                osFieldData += "\"";

                char *pszEscapedVal
                    = CPLEscapeString( pszRawValue,
                                       -1, CPLES_BackslashQuotable );
                osFieldData += pszEscapedVal;
                CPLFree( pszEscapedVal );

                osFieldData += "\"";
            }
            else
                osFieldData += pszRawValue;
        }

        VSIFPrintfL( fp, "# @D%s\n", osFieldData.c_str() );
    }

/* -------------------------------------------------------------------- */
/*      Write Geometry                                                  */
/* -------------------------------------------------------------------- */
    return WriteGeometry( reinterpret_cast<OGRGeometryH>(poGeom), TRUE );
}