Differential D9642 Diff 31337 extern/draco/draco/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.h
Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.h
- This file was moved from extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.h.
| Show First 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | |||||
| bool DynamicIntegerPointsKdTreeEncoder<compression_level_t>::EncodePoints( | bool DynamicIntegerPointsKdTreeEncoder<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_ = static_cast<uint32_t>(end - begin); | num_points_ = static_cast<uint32_t>(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); | EncodeInternal(begin, end); | ||||
| 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 <int compression_level_t> | template <int compression_level_t> | ||||
| template <class RandomAccessIteratorT> | template <class RandomAccessIteratorT> | ||||
| uint32_t | uint32_t | ||||
| DynamicIntegerPointsKdTreeEncoder<compression_level_t>::GetAndEncodeAxis( | DynamicIntegerPointsKdTreeEncoder<compression_level_t>::GetAndEncodeAxis( | ||||
| RandomAccessIteratorT begin, RandomAccessIteratorT end, | RandomAccessIteratorT begin, RandomAccessIteratorT end, | ||||
| const VectorUint32 &old_base, const VectorUint32 &levels, | const VectorUint32 &old_base, const VectorUint32 &levels, | ||||
| uint32_t last_axis) { | uint32_t last_axis) { | ||||
| if (!Policy::select_axis) | if (!Policy::select_axis) { | ||||
| return DRACO_INCREMENT_MOD(last_axis, dimension_); | return DRACO_INCREMENT_MOD(last_axis, dimension_); | ||||
| } | |||||
| // 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 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | while (!status_stack.empty()) { | ||||
| const VectorUint32 &levels = levels_stack_[stack_pos]; | const VectorUint32 &levels = levels_stack_[stack_pos]; | ||||
| const uint32_t axis = | const uint32_t axis = | ||||
| GetAndEncodeAxis(begin, end, old_base, levels, last_axis); | GetAndEncodeAxis(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 = static_cast<uint32_t>(end - begin); | const uint32_t num_remaining_points = static_cast<uint32_t>(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 or 2. | // Fast encoding of remaining bits if number of points is 1 or 2. | ||||
| // 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) { | ||||
| // TODO(hemmer): axes_ not necessary, remove would change bitstream! | // TODO(hemmer): axes_ not necessary, remove would change bitstream! | ||||
| axes_[0] = axis; | axes_[0] = axis; | ||||
| for (uint32_t i = 1; i < dimension_; i++) { | for (uint32_t i = 1; i < dimension_; i++) { | ||||
| axes_[i] = DRACO_INCREMENT_MOD(axes_[i - 1], dimension_); | axes_[i] = DRACO_INCREMENT_MOD(axes_[i - 1], dimension_); | ||||
| Show All 24 Lines | while (!status_stack.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 = static_cast<uint32_t>(split - begin); | const uint32_t first_half = static_cast<uint32_t>(split - begin); | ||||
| const uint32_t second_half = static_cast<uint32_t>(end - split); | const uint32_t second_half = static_cast<uint32_t>(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_stack_[stack_pos][axis] += 1; | levels_stack_[stack_pos][axis] += 1; | ||||
| levels_stack_[stack_pos + 1] = levels_stack_[stack_pos]; // copy | levels_stack_[stack_pos + 1] = levels_stack_[stack_pos]; // copy | ||||
| if (split != begin) | if (split != begin) { | ||||
| status_stack.push(Status(begin, split, axis, stack_pos)); | status_stack.push(Status(begin, split, axis, stack_pos)); | ||||
| if (split != end) | } | ||||
| if (split != end) { | |||||
| status_stack.push(Status(split, end, axis, stack_pos + 1)); | status_stack.push(Status(split, end, axis, stack_pos + 1)); | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| extern template class DynamicIntegerPointsKdTreeEncoder<0>; | extern template class DynamicIntegerPointsKdTreeEncoder<0>; | ||||
| extern template class DynamicIntegerPointsKdTreeEncoder<2>; | extern template class DynamicIntegerPointsKdTreeEncoder<2>; | ||||
| extern template class DynamicIntegerPointsKdTreeEncoder<4>; | extern template class DynamicIntegerPointsKdTreeEncoder<4>; | ||||
| extern template class DynamicIntegerPointsKdTreeEncoder<6>; | extern template class DynamicIntegerPointsKdTreeEncoder<6>; | ||||
| } // namespace draco | } // namespace draco | ||||
| #endif // DRACO_COMPRESSION_POINT_CLOUD_ALGORITHMS_DYNAMIC_INTEGER_POINTS_KD_TREE_ENCODER_H_ | #endif // DRACO_COMPRESSION_POINT_CLOUD_ALGORITHMS_DYNAMIC_INTEGER_POINTS_KD_TREE_ENCODER_H_ | ||||