| 74 | |
| 75 | |
| 76 | void DbWriter::ready(PointTableRef /*table*/) |
| 77 | { |
| 78 | using namespace Dimension; |
| 79 | |
| 80 | // Determine if X, Y and Z values should be written as Signed32 along with |
| 81 | // a scale factor and offset instead of being written as Double. |
| 82 | m_locationScaling = m_scaling.nonstandard(); |
| 83 | |
| 84 | auto cmp = [](const XMLDim& d1, const XMLDim& d2) -> bool |
| 85 | { |
| 86 | long id1 = Utils::toNative(d1.m_dimType.m_id); |
| 87 | long id2 = Utils::toNative(d2.m_dimType.m_id); |
| 88 | |
| 89 | const auto isXyz([](long native)->bool |
| 90 | { |
| 91 | const Id e(static_cast<Id>(native)); |
| 92 | return (e == Id::X || e == Id::Y || e == Id::Z); |
| 93 | }); |
| 94 | |
| 95 | // Put X, Y and Z at the end of the list. |
| 96 | if (isXyz(id1)) |
| 97 | id1 += 1000000; |
| 98 | if (isXyz(id2)) |
| 99 | id2 += 1000000; |
| 100 | return id1 < id2; |
| 101 | }; |
| 102 | |
| 103 | // Sort the dimensions so that X, Y & Z are at the end. |
| 104 | std::sort(m_dbDims.begin(), m_dbDims.end(), cmp); |
| 105 | |
| 106 | // Suck the dimTypes out of the dbDims so that they can be used to |
| 107 | // retrieve data from the point table. |
| 108 | // Set the packed type into the dbDim if necessary and save off the |
| 109 | // index of X, Y and Z for location scaling. |
| 110 | m_dimTypes.clear(); |
| 111 | m_xOffsets = std::make_pair(-1, -1); |
| 112 | m_yOffsets = std::make_pair(-1, -1); |
| 113 | m_zOffsets = std::make_pair(-1, -1); |
| 114 | m_packedPointSize = 0; |
| 115 | m_dbPointSize = 0; |
| 116 | for (auto& xmlDim : m_dbDims) |
| 117 | { |
| 118 | m_dimTypes.push_back(xmlDim.m_dimType); |
| 119 | DimType& dt = m_dimTypes.back(); |
| 120 | // Dim types are stored in the map to allow fast access in readField. |
| 121 | m_dimMap[Utils::toNative(dt.m_id)] = dt; |
| 122 | |
| 123 | if (m_locationScaling) |
| 124 | { |
| 125 | if (xmlDim.m_dimType.m_id == Id::X) |
| 126 | { |
| 127 | xmlDim.m_dimType.m_xform = m_scaling.m_xXform; |
| 128 | xmlDim.m_dimType.m_type = Type::Signed32; |
| 129 | m_xOffsets = |
| 130 | std::make_pair((int)m_packedPointSize, (int)m_dbPointSize); |
| 131 | } |
| 132 | if (xmlDim.m_dimType.m_id == Id::Y) |
| 133 | { |