| 59 | } |
| 60 | |
| 61 | PtxReader::PtxHeader PtxReader::readHeader() |
| 62 | { |
| 63 | // Read header from input stream. Ptx files can have multiple headers per |
| 64 | // file, each with their own column count, row count, scanner posisition and |
| 65 | // scanner transform. The 4x4 transform combines the scanner position |
| 66 | // translation and 3x3 scanner transform afaik. For the sake of this reader |
| 67 | // we actually ignore the scanner position and 3x3 transform and apply the |
| 68 | // 4x4 transform matrix instead. It possibly makes sense to validate the |
| 69 | // scanner position and 3x3 transform is the same as the 4x4 transformation |
| 70 | // matrix. Possibly this is incorrect to assume? |
| 71 | // |
| 72 | // c (Column count) |
| 73 | // r (Row count) |
| 74 | // sx sy sz (Scanner position) |
| 75 | // s11 s21 s31 (Scanner 3x3 transformation matrix) |
| 76 | // s12 s22 s32 |
| 77 | // s13 s23 s33 |
| 78 | // t11 t21 t31 t41 (4x4 transformation matrix) |
| 79 | // t12 t22 t32 t42 |
| 80 | // t13 t23 t33 t43 |
| 81 | // t14 t24 t34 t44 |
| 82 | // |
| 83 | |
| 84 | PtxHeader header; |
| 85 | std::string buf; |
| 86 | |
| 87 | if (!m_istream || !m_istream->good()) |
| 88 | throwError("Unable to read header for file '" + m_filename + "'."); |
| 89 | |
| 90 | // Read column count and row count. |
| 91 | |
| 92 | std::getline(*m_istream, buf); |
| 93 | if (!m_istream->good()) |
| 94 | throwError("Unable to read column size for file '" + m_filename + "'."); |
| 95 | Utils::trim(buf); |
| 96 | if (auto status = Utils::fromString(buf, header.m_columns); !status) |
| 97 | { |
| 98 | throwError("Invalid column size '" + buf + "' in header for file '" + |
| 99 | m_filename + "'. " + status.what()); |
| 100 | } |
| 101 | |
| 102 | std::getline(*m_istream, buf); |
| 103 | if (!m_istream->good()) |
| 104 | throwError("Unable to read row size for file '" + m_filename + "'."); |
| 105 | Utils::trim(buf); |
| 106 | if (auto status = Utils::fromString(buf, header.m_rows); !status) |
| 107 | { |
| 108 | throwError("Invalid row size '" + buf + "' in header for file '" + |
| 109 | m_filename + "'. " + status.what()); |
| 110 | } |
| 111 | |
| 112 | // Skip scanner position and scanner 3x3 transformation matrix. |
| 113 | |
| 114 | for (size_t skip = 0; skip < 4; ++skip) |
| 115 | { |
| 116 | std::getline(*m_istream, buf); |
| 117 | if (!m_istream->good()) |
| 118 | { |
nothing calls this directly
no test coverage detected