Exemple #1
0
/// Read a point's data packed into a buffer.
/// \param[in] pb  Point buffer to read from.
/// \param[in] idx  Index of point to read.
/// \param[in] outbuf  Buffer to write to.
/// \return  Number of bytes written to buffer.
size_t DbWriter::readPoint(const PointBuffer& pb, PointId idx, char *outbuf)
{
    pb.getPackedPoint(m_dimTypes, idx, outbuf);
    
    auto iconvert = [](const XForm& xform, const char *inpos, char *outpos)
    {
        double d;
        int32_t i;

        memcpy(&d, inpos, sizeof(double));
        d = (d - xform.m_offset) / xform.m_scale;
        i = boost::numeric_cast<int32_t>(lround(d));
        memcpy(outpos, &i, sizeof(int32_t));
    };

    if (m_locationScaling)
    {
        int outOffset;

        if (m_xPackedOffset >= 0)
            outOffset = m_xPackedOffset;
        else if (m_yPackedOffset >= 0)
            outOffset = m_yPackedOffset;
        else if (m_zPackedOffset >= 0)
            outOffset = m_zPackedOffset;
        else
            outOffset = m_packedPointSize;  //So we return the proper size.

        if (m_xPackedOffset >= 0)
        {
            iconvert(m_xXform, outbuf + m_xPackedOffset, outbuf + outOffset);
            outOffset += sizeof(int);
        }
        if (m_yPackedOffset >= 0)
        {
            iconvert(m_yXform, outbuf + m_yPackedOffset, outbuf + outOffset);
            outOffset += sizeof(int);
        }
        if (m_zPackedOffset >= 0)
        {
            iconvert(m_zXform, outbuf + m_zPackedOffset, outbuf + outOffset);
            outOffset += sizeof(int);
        }
        return outOffset;
    }
    else
        return m_packedPointSize;
}