| 123 | |
| 124 | |
| 125 | point_count_t PtsReader::read(PointViewPtr view, point_count_t numPts) |
| 126 | { |
| 127 | PointId idx = view->size(); |
| 128 | |
| 129 | point_count_t cnt = 0; |
| 130 | size_t line = 1; |
| 131 | |
| 132 | // Continue reading while count less than max points and count less than |
| 133 | // the expected point count. |
| 134 | while (m_istream->good() && cnt < numPts && cnt < m_PointCount) |
| 135 | { |
| 136 | std::string buf; |
| 137 | StringList fields; |
| 138 | |
| 139 | std::getline(*m_istream, buf); |
| 140 | line++; |
| 141 | if (buf.empty()) |
| 142 | continue; |
| 143 | |
| 144 | fields = Utils::split2(buf, m_separator); |
| 145 | if (fields.size() != m_dims.size()) |
| 146 | { |
| 147 | log()->get(LogLevel::Error) << "Line " << line << |
| 148 | " in '" << m_filename << "' contains " << fields.size() << |
| 149 | " fields when " << m_dims.size() << " were expected. " |
| 150 | "Ignoring." << std::endl; |
| 151 | continue; |
| 152 | } |
| 153 | |
| 154 | double d; |
| 155 | for (size_t i = 0; i < fields.size(); ++i) |
| 156 | { |
| 157 | if (!Utils::fromString(fields[i], d)) |
| 158 | { |
| 159 | log()->get(LogLevel::Error) << "Can't convert " |
| 160 | "field '" << fields[i] << "' to numeric value on line " << |
| 161 | line << " in '" << m_filename << "'. Setting to 0." << |
| 162 | std::endl; |
| 163 | d = 0; |
| 164 | } |
| 165 | if (i == 3) // Intensity field in PTS is -2048 to 2047, we map to 0 4095 |
| 166 | { |
| 167 | d += 2048; |
| 168 | } |
| 169 | view->setField(m_dims[i], idx, d); |
| 170 | } |
| 171 | cnt++; |
| 172 | idx++; |
| 173 | } |
| 174 | |
| 175 | if(cnt < m_PointCount) |
| 176 | { |
| 177 | log()->get(LogLevel::Warning) << "Expected " << m_PointCount |
| 178 | << " points but only " << cnt << " were found." << std::endl; |
| 179 | } |
| 180 | |
| 181 | return cnt; |
| 182 | } |