Differential D9642 Diff 31697 extern/draco/draco/src/draco/compression/attributes/sequential_integer_attribute_encoder.cc
Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/compression/attributes/sequential_integer_attribute_encoder.cc
- This file was moved from extern/draco/dracoenc/src/draco/compression/attributes/sequential_integer_attribute_encoder.cc.
| Show All 19 Lines | |||||
| #include "draco/core/bit_utils.h" | #include "draco/core/bit_utils.h" | ||||
| namespace draco { | namespace draco { | ||||
| SequentialIntegerAttributeEncoder::SequentialIntegerAttributeEncoder() {} | SequentialIntegerAttributeEncoder::SequentialIntegerAttributeEncoder() {} | ||||
| bool SequentialIntegerAttributeEncoder::Init(PointCloudEncoder *encoder, | bool SequentialIntegerAttributeEncoder::Init(PointCloudEncoder *encoder, | ||||
| int attribute_id) { | int attribute_id) { | ||||
| if (!SequentialAttributeEncoder::Init(encoder, attribute_id)) | if (!SequentialAttributeEncoder::Init(encoder, attribute_id)) { | ||||
| return false; | return false; | ||||
| } | |||||
| if (GetUniqueId() == SEQUENTIAL_ATTRIBUTE_ENCODER_INTEGER) { | if (GetUniqueId() == SEQUENTIAL_ATTRIBUTE_ENCODER_INTEGER) { | ||||
| // When encoding integers, this encoder currently works only for integer | // When encoding integers, this encoder currently works only for integer | ||||
| // attributes up to 32 bits. | // attributes up to 32 bits. | ||||
| switch (attribute()->data_type()) { | switch (attribute()->data_type()) { | ||||
| case DT_INT8: | case DT_INT8: | ||||
| case DT_UINT8: | case DT_UINT8: | ||||
| case DT_INT16: | case DT_INT16: | ||||
| case DT_UINT16: | case DT_UINT16: | ||||
| Show All 15 Lines | bool SequentialIntegerAttributeEncoder::Init(PointCloudEncoder *encoder, | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| bool SequentialIntegerAttributeEncoder::TransformAttributeToPortableFormat( | bool SequentialIntegerAttributeEncoder::TransformAttributeToPortableFormat( | ||||
| const std::vector<PointIndex> &point_ids) { | const std::vector<PointIndex> &point_ids) { | ||||
| if (encoder()) { | if (encoder()) { | ||||
| if (!PrepareValues(point_ids, encoder()->point_cloud()->num_points())) | if (!PrepareValues(point_ids, encoder()->point_cloud()->num_points())) { | ||||
| return false; | return false; | ||||
| } | |||||
| } else { | } else { | ||||
| if (!PrepareValues(point_ids, 0)) | if (!PrepareValues(point_ids, 0)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | |||||
| // Update point to attribute mapping with the portable attribute if the | // Update point to attribute mapping with the portable attribute if the | ||||
| // attribute is a parent attribute (for now, we can skip it otherwise). | // attribute is a parent attribute (for now, we can skip it otherwise). | ||||
| if (is_parent_encoder()) { | if (is_parent_encoder()) { | ||||
| // First create map between original attribute value indices and new ones | // First create map between original attribute value indices and new ones | ||||
| // (determined by the encoding order). | // (determined by the encoding order). | ||||
| const PointAttribute *const orig_att = attribute(); | const PointAttribute *const orig_att = attribute(); | ||||
| PointAttribute *const portable_att = portable_attribute(); | PointAttribute *const portable_att = portable_attribute(); | ||||
| Show All 20 Lines | return CreatePredictionSchemeForEncoder< | ||||
| int32_t, PredictionSchemeWrapEncodingTransform<int32_t>>( | int32_t, PredictionSchemeWrapEncodingTransform<int32_t>>( | ||||
| method, attribute_id(), encoder()); | method, attribute_id(), encoder()); | ||||
| } | } | ||||
| bool SequentialIntegerAttributeEncoder::EncodeValues( | bool SequentialIntegerAttributeEncoder::EncodeValues( | ||||
| const std::vector<PointIndex> &point_ids, EncoderBuffer *out_buffer) { | const std::vector<PointIndex> &point_ids, EncoderBuffer *out_buffer) { | ||||
| // Initialize general quantization data. | // Initialize general quantization data. | ||||
| const PointAttribute *const attrib = attribute(); | const PointAttribute *const attrib = attribute(); | ||||
| if (attrib->size() == 0) | if (attrib->size() == 0) { | ||||
| return true; | return true; | ||||
| } | |||||
| int8_t prediction_scheme_method = PREDICTION_NONE; | int8_t prediction_scheme_method = PREDICTION_NONE; | ||||
| if (prediction_scheme_) { | if (prediction_scheme_) { | ||||
| if (!SetPredictionSchemeParentAttributes(prediction_scheme_.get())) { | if (!SetPredictionSchemeParentAttributes(prediction_scheme_.get())) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| prediction_scheme_method = | prediction_scheme_method = | ||||
| static_cast<int8_t>(prediction_scheme_->GetPredictionMethod()); | static_cast<int8_t>(prediction_scheme_->GetPredictionMethod()); | ||||
| ▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | bool SequentialIntegerAttributeEncoder::PrepareValues( | ||||
| const int num_components = attrib->num_components(); | const int num_components = attrib->num_components(); | ||||
| const int num_entries = static_cast<int>(point_ids.size()); | const int num_entries = static_cast<int>(point_ids.size()); | ||||
| PreparePortableAttribute(num_entries, num_components, num_points); | PreparePortableAttribute(num_entries, num_components, num_points); | ||||
| int32_t dst_index = 0; | int32_t dst_index = 0; | ||||
| int32_t *const portable_attribute_data = GetPortableAttributeData(); | int32_t *const portable_attribute_data = GetPortableAttributeData(); | ||||
| for (PointIndex pi : point_ids) { | for (PointIndex pi : point_ids) { | ||||
| const AttributeValueIndex att_id = attrib->mapped_index(pi); | const AttributeValueIndex att_id = attrib->mapped_index(pi); | ||||
| if (!attrib->ConvertValue<int32_t>(att_id, | if (!attrib->ConvertValue<int32_t>(att_id, | ||||
| portable_attribute_data + dst_index)) | portable_attribute_data + dst_index)) { | ||||
| return false; | return false; | ||||
| } | |||||
| dst_index += num_components; | dst_index += num_components; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| void SequentialIntegerAttributeEncoder::PreparePortableAttribute( | void SequentialIntegerAttributeEncoder::PreparePortableAttribute( | ||||
| int num_entries, int num_components, int num_points) { | int num_entries, int num_components, int num_points) { | ||||
| GeometryAttribute va; | GeometryAttribute va; | ||||
| Show All 11 Lines | |||||