Differential D9642 Diff 31697 extern/draco/draco/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_encoder.h
Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_encoder.h
- This file was moved from extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_encoder.h.
| Show First 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | |||||
| bool IntegerPointsKdTreeEncoder<PointDiT, compression_level_t>::EncodePoints( | bool IntegerPointsKdTreeEncoder<PointDiT, compression_level_t>::EncodePoints( | ||||
| RandomAccessIteratorT begin, RandomAccessIteratorT end, | RandomAccessIteratorT begin, RandomAccessIteratorT end, | ||||
| const uint32_t &bit_length, EncoderBuffer *buffer) { | const uint32_t &bit_length, EncoderBuffer *buffer) { | ||||
| bit_length_ = bit_length; | bit_length_ = bit_length; | ||||
| num_points_ = end - begin; | num_points_ = end - begin; | ||||
| buffer->Encode(bit_length_); | buffer->Encode(bit_length_); | ||||
| buffer->Encode(num_points_); | buffer->Encode(num_points_); | ||||
| if (num_points_ == 0) | if (num_points_ == 0) { | ||||
| return true; | return true; | ||||
| } | |||||
| numbers_encoder_.StartEncoding(); | numbers_encoder_.StartEncoding(); | ||||
| remaining_bits_encoder_.StartEncoding(); | remaining_bits_encoder_.StartEncoding(); | ||||
| axis_encoder_.StartEncoding(); | axis_encoder_.StartEncoding(); | ||||
| half_encoder_.StartEncoding(); | half_encoder_.StartEncoding(); | ||||
| EncodeInternal(begin, end, PointTraits<PointDiT>::Origin(), | EncodeInternal(begin, end, PointTraits<PointDiT>::Origin(), | ||||
| PointTraits<PointDiT>::ZeroArray(), 0); | PointTraits<PointDiT>::ZeroArray(), 0); | ||||
| numbers_encoder_.EndEncoding(buffer); | numbers_encoder_.EndEncoding(buffer); | ||||
| remaining_bits_encoder_.EndEncoding(buffer); | remaining_bits_encoder_.EndEncoding(buffer); | ||||
| axis_encoder_.EndEncoding(buffer); | axis_encoder_.EndEncoding(buffer); | ||||
| half_encoder_.EndEncoding(buffer); | half_encoder_.EndEncoding(buffer); | ||||
| return true; | return true; | ||||
| } | } | ||||
| template <class PointDiT, int compression_level_t> | template <class PointDiT, int compression_level_t> | ||||
| template <class RandomAccessIteratorT> | template <class RandomAccessIteratorT> | ||||
| uint32_t IntegerPointsKdTreeEncoder<PointDiT, compression_level_t>::GetAxis( | uint32_t IntegerPointsKdTreeEncoder<PointDiT, compression_level_t>::GetAxis( | ||||
| RandomAccessIteratorT begin, RandomAccessIteratorT end, | RandomAccessIteratorT begin, RandomAccessIteratorT end, | ||||
| const PointDiT &old_base, std::array<uint32_t, D> levels, | const PointDiT &old_base, std::array<uint32_t, D> levels, | ||||
| uint32_t last_axis) { | uint32_t last_axis) { | ||||
| if (!Policy::select_axis) | if (!Policy::select_axis) { | ||||
| return DRACO_INCREMENT_MOD(last_axis, D); | return DRACO_INCREMENT_MOD(last_axis, D); | ||||
| } | |||||
| // For many points this function selects the axis that should be used | // For many points this function selects the axis that should be used | ||||
| // for the split by keeping as many points as possible bundled. | // for the split by keeping as many points as possible bundled. | ||||
| // In the best case we do not split the point cloud at all. | // In the best case we do not split the point cloud at all. | ||||
| // For lower number of points, we simply choose the axis that is refined the | // For lower number of points, we simply choose the axis that is refined the | ||||
| // least so far. | // least so far. | ||||
| DRACO_DCHECK_EQ(true, end - begin != 0); | DRACO_DCHECK_EQ(true, end - begin != 0); | ||||
| Show All 10 Lines | if (end - begin < 64) { | ||||
| std::array<uint32_t, D> num_remaining_bits = | std::array<uint32_t, D> num_remaining_bits = | ||||
| PointTraits<PointDiT>::ZeroArray(); | PointTraits<PointDiT>::ZeroArray(); | ||||
| for (int i = 0; i < D; i++) { | for (int i = 0; i < D; i++) { | ||||
| num_remaining_bits[i] = bit_length_ - levels[i]; | num_remaining_bits[i] = bit_length_ - levels[i]; | ||||
| } | } | ||||
| PointDiT split(old_base); | PointDiT split(old_base); | ||||
| for (int i = 0; i < D; i++) { | for (int i = 0; i < D; i++) { | ||||
| if (num_remaining_bits[i]) | if (num_remaining_bits[i]) { | ||||
| split[i] += 1 << (num_remaining_bits[i] - 1); | split[i] += 1 << (num_remaining_bits[i] - 1); | ||||
| } | } | ||||
| } | |||||
| std::array<uint32_t, D> deviations = PointTraits<PointDiT>::ZeroArray(); | std::array<uint32_t, D> deviations = PointTraits<PointDiT>::ZeroArray(); | ||||
| for (auto it = begin; it != end; ++it) { | for (auto it = begin; it != end; ++it) { | ||||
| for (int i = 0; i < D; i++) { | for (int i = 0; i < D; i++) { | ||||
| deviations[i] += ((*it)[i] < split[i]); | deviations[i] += ((*it)[i] < split[i]); | ||||
| } | } | ||||
| } | } | ||||
| for (int i = 0; i < D; i++) { | for (int i = 0; i < D; i++) { | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | while (!status_q.empty()) { | ||||
| levels = status.levels; | levels = status.levels; | ||||
| last_axis = status.last_axis; | last_axis = status.last_axis; | ||||
| const uint32_t axis = GetAxis(begin, end, old_base, levels, last_axis); | const uint32_t axis = GetAxis(begin, end, old_base, levels, last_axis); | ||||
| const uint32_t level = levels[axis]; | const uint32_t level = levels[axis]; | ||||
| const uint32_t num_remaining_points = end - begin; | const uint32_t num_remaining_points = end - begin; | ||||
| // If this happens all axis are subdivided to the end. | // If this happens all axis are subdivided to the end. | ||||
| if ((bit_length_ - level) == 0) | if ((bit_length_ - level) == 0) { | ||||
| continue; | continue; | ||||
| } | |||||
| // Fast encoding of remaining bits if number of points is 1. | // Fast encoding of remaining bits if number of points is 1. | ||||
| // Doing this also for 2 gives a slight additional speed up. | // Doing this also for 2 gives a slight additional speed up. | ||||
| if (num_remaining_points <= 2) { | if (num_remaining_points <= 2) { | ||||
| std::array<uint32_t, D> axes; | std::array<uint32_t, D> axes; | ||||
| axes[0] = axis; | axes[0] = axis; | ||||
| for (int i = 1; i < D; i++) { | for (int i = 1; i < D; i++) { | ||||
| axes[i] = DRACO_INCREMENT_MOD(axes[i - 1], D); | axes[i] = DRACO_INCREMENT_MOD(axes[i - 1], D); | ||||
| Show All 27 Lines | while (!status_q.empty()) { | ||||
| // Encode number of points in first and second half. | // Encode number of points in first and second half. | ||||
| const int required_bits = MostSignificantBit(num_remaining_points); | const int required_bits = MostSignificantBit(num_remaining_points); | ||||
| const uint32_t first_half = split - begin; | const uint32_t first_half = split - begin; | ||||
| const uint32_t second_half = end - split; | const uint32_t second_half = end - split; | ||||
| const bool left = first_half < second_half; | const bool left = first_half < second_half; | ||||
| if (first_half != second_half) | if (first_half != second_half) { | ||||
| half_encoder_.EncodeBit(left); | half_encoder_.EncodeBit(left); | ||||
| } | |||||
| if (left) { | if (left) { | ||||
| EncodeNumber(required_bits, num_remaining_points / 2 - first_half); | EncodeNumber(required_bits, num_remaining_points / 2 - first_half); | ||||
| } else { | } else { | ||||
| EncodeNumber(required_bits, num_remaining_points / 2 - second_half); | EncodeNumber(required_bits, num_remaining_points / 2 - second_half); | ||||
| } | } | ||||
| levels[axis] += 1; | levels[axis] += 1; | ||||
| if (split != begin) | if (split != begin) { | ||||
| status_q.push(EncodingStatus<RandomAccessIteratorT>( | status_q.push(EncodingStatus<RandomAccessIteratorT>( | ||||
| begin, split, old_base, levels, axis)); | begin, split, old_base, levels, axis)); | ||||
| if (split != end) | } | ||||
| if (split != end) { | |||||
| status_q.push(EncodingStatus<RandomAccessIteratorT>(split, end, new_base, | status_q.push(EncodingStatus<RandomAccessIteratorT>(split, end, new_base, | ||||
| levels, axis)); | levels, axis)); | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| extern template class IntegerPointsKdTreeEncoder<Point3ui, 0>; | extern template class IntegerPointsKdTreeEncoder<Point3ui, 0>; | ||||
| extern template class IntegerPointsKdTreeEncoder<Point3ui, 1>; | extern template class IntegerPointsKdTreeEncoder<Point3ui, 1>; | ||||
| extern template class IntegerPointsKdTreeEncoder<Point3ui, 2>; | extern template class IntegerPointsKdTreeEncoder<Point3ui, 2>; | ||||
| extern template class IntegerPointsKdTreeEncoder<Point3ui, 3>; | extern template class IntegerPointsKdTreeEncoder<Point3ui, 3>; | ||||
| extern template class IntegerPointsKdTreeEncoder<Point3ui, 4>; | extern template class IntegerPointsKdTreeEncoder<Point3ui, 4>; | ||||
| extern template class IntegerPointsKdTreeEncoder<Point3ui, 5>; | extern template class IntegerPointsKdTreeEncoder<Point3ui, 5>; | ||||
| extern template class IntegerPointsKdTreeEncoder<Point3ui, 6>; | extern template class IntegerPointsKdTreeEncoder<Point3ui, 6>; | ||||
| extern template class IntegerPointsKdTreeEncoder<Point3ui, 7>; | extern template class IntegerPointsKdTreeEncoder<Point3ui, 7>; | ||||
| extern template class IntegerPointsKdTreeEncoder<Point3ui, 8>; | extern template class IntegerPointsKdTreeEncoder<Point3ui, 8>; | ||||
| extern template class IntegerPointsKdTreeEncoder<Point3ui, 9>; | extern template class IntegerPointsKdTreeEncoder<Point3ui, 9>; | ||||
| extern template class IntegerPointsKdTreeEncoder<Point3ui, 10>; | extern template class IntegerPointsKdTreeEncoder<Point3ui, 10>; | ||||
| } // namespace draco | } // namespace draco | ||||
| #endif // DRACO_COMPRESSION_POINT_CLOUD_ALGORITHMS_INTEGER_POINTS_KD_TREE_ENCODER_H_ | #endif // DRACO_COMPRESSION_POINT_CLOUD_ALGORITHMS_INTEGER_POINTS_KD_TREE_ENCODER_H_ | ||||