Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/attributes/point_attribute.cc
- This file was moved from extern/draco/dracoenc/src/draco/attributes/point_attribute.cc.
| Show All 26 Lines | |||||
| PointAttribute::PointAttribute() | PointAttribute::PointAttribute() | ||||
| : num_unique_entries_(0), identity_mapping_(false) {} | : num_unique_entries_(0), identity_mapping_(false) {} | ||||
| PointAttribute::PointAttribute(const GeometryAttribute &att) | PointAttribute::PointAttribute(const GeometryAttribute &att) | ||||
| : GeometryAttribute(att), | : GeometryAttribute(att), | ||||
| num_unique_entries_(0), | num_unique_entries_(0), | ||||
| identity_mapping_(false) {} | identity_mapping_(false) {} | ||||
| void PointAttribute::Init(Type attribute_type, int8_t num_components, | |||||
| DataType data_type, bool normalized, | |||||
| size_t num_attribute_values) { | |||||
| attribute_buffer_ = std::unique_ptr<DataBuffer>(new DataBuffer()); | |||||
| GeometryAttribute::Init(attribute_type, attribute_buffer_.get(), | |||||
| num_components, data_type, normalized, | |||||
| DataTypeLength(data_type) * num_components, 0); | |||||
| Reset(num_attribute_values); | |||||
| SetIdentityMapping(); | |||||
| } | |||||
| void PointAttribute::CopyFrom(const PointAttribute &src_att) { | void PointAttribute::CopyFrom(const PointAttribute &src_att) { | ||||
| if (buffer() == nullptr) { | if (buffer() == nullptr) { | ||||
| // If the destination attribute doesn't have a valid buffer, create it. | // If the destination attribute doesn't have a valid buffer, create it. | ||||
| attribute_buffer_ = std::unique_ptr<DataBuffer>(new DataBuffer()); | attribute_buffer_ = std::unique_ptr<DataBuffer>(new DataBuffer()); | ||||
| ResetBuffer(attribute_buffer_.get(), 0, 0); | ResetBuffer(attribute_buffer_.get(), 0, 0); | ||||
| } | } | ||||
| if (!GeometryAttribute::CopyFrom(src_att)) | if (!GeometryAttribute::CopyFrom(src_att)) { | ||||
| return; | return; | ||||
| } | |||||
| identity_mapping_ = src_att.identity_mapping_; | identity_mapping_ = src_att.identity_mapping_; | ||||
| num_unique_entries_ = src_att.num_unique_entries_; | num_unique_entries_ = src_att.num_unique_entries_; | ||||
| indices_map_ = src_att.indices_map_; | indices_map_ = src_att.indices_map_; | ||||
| if (src_att.attribute_transform_data_) { | if (src_att.attribute_transform_data_) { | ||||
| attribute_transform_data_ = std::unique_ptr<AttributeTransformData>( | attribute_transform_data_ = std::unique_ptr<AttributeTransformData>( | ||||
| new AttributeTransformData(*src_att.attribute_transform_data_.get())); | new AttributeTransformData(*src_att.attribute_transform_data_)); | ||||
| } else { | } else { | ||||
| attribute_transform_data_ = nullptr; | attribute_transform_data_ = nullptr; | ||||
| } | } | ||||
| } | } | ||||
| bool PointAttribute::Reset(size_t num_attribute_values) { | bool PointAttribute::Reset(size_t num_attribute_values) { | ||||
| if (attribute_buffer_ == nullptr) { | if (attribute_buffer_ == nullptr) { | ||||
| attribute_buffer_ = std::unique_ptr<DataBuffer>(new DataBuffer()); | attribute_buffer_ = std::unique_ptr<DataBuffer>(new DataBuffer()); | ||||
| } | } | ||||
| const int64_t entry_size = DataTypeLength(data_type()) * num_components(); | const int64_t entry_size = DataTypeLength(data_type()) * num_components(); | ||||
| if (!attribute_buffer_->Update(nullptr, num_attribute_values * entry_size)) | if (!attribute_buffer_->Update(nullptr, num_attribute_values * entry_size)) { | ||||
| return false; | return false; | ||||
| } | |||||
| // Assign the new buffer to the parent attribute. | // Assign the new buffer to the parent attribute. | ||||
| ResetBuffer(attribute_buffer_.get(), entry_size, 0); | ResetBuffer(attribute_buffer_.get(), entry_size, 0); | ||||
| num_unique_entries_ = static_cast<uint32_t>(num_attribute_values); | num_unique_entries_ = static_cast<uint32_t>(num_attribute_values); | ||||
| return true; | return true; | ||||
| } | } | ||||
| void PointAttribute::Resize(size_t new_num_unique_entries) { | |||||
| num_unique_entries_ = static_cast<uint32_t>(new_num_unique_entries); | |||||
| attribute_buffer_->Resize(new_num_unique_entries * byte_stride()); | |||||
| } | |||||
| #ifdef DRACO_ATTRIBUTE_VALUES_DEDUPLICATION_SUPPORTED | #ifdef DRACO_ATTRIBUTE_VALUES_DEDUPLICATION_SUPPORTED | ||||
| AttributeValueIndex::ValueType PointAttribute::DeduplicateValues( | AttributeValueIndex::ValueType PointAttribute::DeduplicateValues( | ||||
| const GeometryAttribute &in_att) { | const GeometryAttribute &in_att) { | ||||
| return DeduplicateValues(in_att, AttributeValueIndex(0)); | return DeduplicateValues(in_att, AttributeValueIndex(0)); | ||||
| } | } | ||||
| AttributeValueIndex::ValueType PointAttribute::DeduplicateValues( | AttributeValueIndex::ValueType PointAttribute::DeduplicateValues( | ||||
| const GeometryAttribute &in_att, AttributeValueIndex in_att_offset) { | const GeometryAttribute &in_att, AttributeValueIndex in_att_offset) { | ||||
| Show All 20 Lines | case DT_UINT32: | ||||
| unique_vals = DeduplicateTypedValues<uint32_t>(in_att, in_att_offset); | unique_vals = DeduplicateTypedValues<uint32_t>(in_att, in_att_offset); | ||||
| break; | break; | ||||
| case DT_INT32: | case DT_INT32: | ||||
| unique_vals = DeduplicateTypedValues<int32_t>(in_att, in_att_offset); | unique_vals = DeduplicateTypedValues<int32_t>(in_att, in_att_offset); | ||||
| break; | break; | ||||
| default: | default: | ||||
| return -1; // Unsupported data type. | return -1; // Unsupported data type. | ||||
| } | } | ||||
| if (unique_vals == 0) | if (unique_vals == 0) { | ||||
| return -1; // Unexpected error. | return -1; // Unexpected error. | ||||
| } | |||||
| return unique_vals; | return unique_vals; | ||||
| } | } | ||||
| // Helper function for calling UnifyDuplicateAttributes<T,num_components_t> | // Helper function for calling UnifyDuplicateAttributes<T,num_components_t> | ||||
| // with the correct template arguments. | // with the correct template arguments. | ||||
| // Returns the number of unique attribute values. | // Returns the number of unique attribute values. | ||||
| template <typename T> | template <typename T> | ||||
| AttributeValueIndex::ValueType PointAttribute::DeduplicateTypedValues( | AttributeValueIndex::ValueType PointAttribute::DeduplicateTypedValues( | ||||
| ▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | if (it != value_to_index_map.end()) { | ||||
| // Add the unique value to the mesh builder. | // Add the unique value to the mesh builder. | ||||
| SetAttributeValue(unique_vals, &att_value); | SetAttributeValue(unique_vals, &att_value); | ||||
| // Update index mapping. | // Update index mapping. | ||||
| value_map[i] = unique_vals; | value_map[i] = unique_vals; | ||||
| ++unique_vals; | ++unique_vals; | ||||
| } | } | ||||
| } | } | ||||
| if (unique_vals == num_unique_entries_) | if (unique_vals == num_unique_entries_) { | ||||
| return unique_vals.value(); // Nothing has changed. | return unique_vals.value(); // Nothing has changed. | ||||
| } | |||||
| if (is_mapping_identity()) { | if (is_mapping_identity()) { | ||||
| // Change identity mapping to the explicit one. | // Change identity mapping to the explicit one. | ||||
| // The number of points is equal to the number of old unique values. | // The number of points is equal to the number of old unique values. | ||||
| SetExplicitMapping(num_unique_entries_); | SetExplicitMapping(num_unique_entries_); | ||||
| // Update the explicit map. | // Update the explicit map. | ||||
| for (uint32_t i = 0; i < num_unique_entries_; ++i) { | for (uint32_t i = 0; i < num_unique_entries_; ++i) { | ||||
| SetPointMapEntry(PointIndex(i), value_map[AttributeValueIndex(i)]); | SetPointMapEntry(PointIndex(i), value_map[AttributeValueIndex(i)]); | ||||
| } | } | ||||
| Show All 12 Lines | |||||