Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/attributes/point_attribute.h
- This file was moved from extern/draco/dracoenc/src/draco/attributes/point_attribute.h.
| Show All 11 Lines | |||||
| // See the License for the specific language governing permissions and | // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | // limitations under the License. | ||||
| // | // | ||||
| #ifndef DRACO_ATTRIBUTES_POINT_ATTRIBUTE_H_ | #ifndef DRACO_ATTRIBUTES_POINT_ATTRIBUTE_H_ | ||||
| #define DRACO_ATTRIBUTES_POINT_ATTRIBUTE_H_ | #define DRACO_ATTRIBUTES_POINT_ATTRIBUTE_H_ | ||||
| #include <memory> | #include <memory> | ||||
| #include "draco/draco_features.h" | |||||
| #include "draco/attributes/attribute_transform_data.h" | #include "draco/attributes/attribute_transform_data.h" | ||||
| #include "draco/attributes/geometry_attribute.h" | #include "draco/attributes/geometry_attribute.h" | ||||
| #include "draco/core/draco_index_type_vector.h" | #include "draco/core/draco_index_type_vector.h" | ||||
| #include "draco/core/hash_utils.h" | #include "draco/core/hash_utils.h" | ||||
| #include "draco/core/macros.h" | #include "draco/core/macros.h" | ||||
| #include "draco/draco_features.h" | |||||
| namespace draco { | namespace draco { | ||||
| // Class for storing point specific data about each attribute. In general, | // Class for storing point specific data about each attribute. In general, | ||||
| // multiple points stored in a point cloud can share the same attribute value | // multiple points stored in a point cloud can share the same attribute value | ||||
| // and this class provides the necessary mapping between point ids and attribute | // and this class provides the necessary mapping between point ids and attribute | ||||
| // value ids. | // value ids. | ||||
| class PointAttribute : public GeometryAttribute { | class PointAttribute : public GeometryAttribute { | ||||
| public: | public: | ||||
| PointAttribute(); | PointAttribute(); | ||||
| explicit PointAttribute(const GeometryAttribute &att); | explicit PointAttribute(const GeometryAttribute &att); | ||||
| // Make sure the move constructor is defined (needed for better performance | // Make sure the move constructor is defined (needed for better performance | ||||
| // when new attributes are added to PointCloud). | // when new attributes are added to PointCloud). | ||||
| PointAttribute(PointAttribute &&attribute) = default; | PointAttribute(PointAttribute &&attribute) = default; | ||||
| PointAttribute &operator=(PointAttribute &&attribute) = default; | PointAttribute &operator=(PointAttribute &&attribute) = default; | ||||
| // Initializes a point attribute. By default the attribute will be set to | |||||
| // identity mapping between point indices and attribute values. To set custom | |||||
| // mapping use SetExplicitMapping() function. | |||||
| void Init(Type attribute_type, int8_t num_components, DataType data_type, | |||||
| bool normalized, size_t num_attribute_values); | |||||
| // Copies attribute data from the provided |src_att| attribute. | // Copies attribute data from the provided |src_att| attribute. | ||||
| void CopyFrom(const PointAttribute &src_att); | void CopyFrom(const PointAttribute &src_att); | ||||
| // Prepares the attribute storage for the specified number of entries. | // Prepares the attribute storage for the specified number of entries. | ||||
| bool Reset(size_t num_attribute_values); | bool Reset(size_t num_attribute_values); | ||||
| size_t size() const { return num_unique_entries_; } | size_t size() const { return num_unique_entries_; } | ||||
| AttributeValueIndex mapped_index(PointIndex point_index) const { | AttributeValueIndex mapped_index(PointIndex point_index) const { | ||||
| if (identity_mapping_) | if (identity_mapping_) { | ||||
| return AttributeValueIndex(point_index.value()); | return AttributeValueIndex(point_index.value()); | ||||
| } | |||||
| return indices_map_[point_index]; | return indices_map_[point_index]; | ||||
| } | } | ||||
| DataBuffer *buffer() const { return attribute_buffer_.get(); } | DataBuffer *buffer() const { return attribute_buffer_.get(); } | ||||
| bool is_mapping_identity() const { return identity_mapping_; } | bool is_mapping_identity() const { return identity_mapping_; } | ||||
| size_t indices_map_size() const { | size_t indices_map_size() const { | ||||
| if (is_mapping_identity()) | if (is_mapping_identity()) { | ||||
| return 0; | return 0; | ||||
| } | |||||
| return indices_map_.size(); | return indices_map_.size(); | ||||
| } | } | ||||
| const uint8_t *GetAddressOfMappedIndex(PointIndex point_index) const { | const uint8_t *GetAddressOfMappedIndex(PointIndex point_index) const { | ||||
| return GetAddress(mapped_index(point_index)); | return GetAddress(mapped_index(point_index)); | ||||
| } | } | ||||
| // Sets the new number of unique attribute entries for the attribute. | // Sets the new number of unique attribute entries for the attribute. The | ||||
| void Resize(size_t new_num_unique_entries) { | // function resizes the attribute storage to hold |num_attribute_values| | ||||
| num_unique_entries_ = static_cast<uint32_t>(new_num_unique_entries); | // entries. | ||||
| } | // All previous entries with AttributeValueIndex < |num_attribute_values| | ||||
| // are preserved. Caller needs to ensure that the PointAttribute is still | |||||
| // valid after the resizing operation (that is, each point is mapped to a | |||||
| // valid attribute value). | |||||
| void Resize(size_t new_num_unique_entries); | |||||
| // Functions for setting the type of mapping between point indices and | // Functions for setting the type of mapping between point indices and | ||||
| // attribute entry ids. | // attribute entry ids. | ||||
| // This function sets the mapping to implicit, where point indices are equal | // This function sets the mapping to implicit, where point indices are equal | ||||
| // to attribute entry indices. | // to attribute entry indices. | ||||
| void SetIdentityMapping() { | void SetIdentityMapping() { | ||||
| identity_mapping_ = true; | identity_mapping_ = true; | ||||
| indices_map_.clear(); | indices_map_.clear(); | ||||
| } | } | ||||
| // This function sets the mapping to be explicitly using the indices_map_ | // This function sets the mapping to be explicitly using the indices_map_ | ||||
| // array that needs to be initialized by the caller. | // array that needs to be initialized by the caller. | ||||
| void SetExplicitMapping(size_t num_points) { | void SetExplicitMapping(size_t num_points) { | ||||
| identity_mapping_ = false; | identity_mapping_ = false; | ||||
| indices_map_.resize(num_points, kInvalidAttributeValueIndex); | indices_map_.resize(num_points, kInvalidAttributeValueIndex); | ||||
| } | } | ||||
| // Set an explicit map entry for a specific point index. | // Set an explicit map entry for a specific point index. | ||||
| void SetPointMapEntry(PointIndex point_index, | void SetPointMapEntry(PointIndex point_index, | ||||
| AttributeValueIndex entry_index) { | AttributeValueIndex entry_index) { | ||||
| DRACO_DCHECK(!identity_mapping_); | DRACO_DCHECK(!identity_mapping_); | ||||
| indices_map_[point_index] = entry_index; | indices_map_[point_index] = entry_index; | ||||
| } | } | ||||
| // Sets a value of an attribute entry. The input value must be allocated to | |||||
| // cover all components of a single attribute entry. | |||||
| void SetAttributeValue(AttributeValueIndex entry_index, const void *value) { | |||||
| const int64_t byte_pos = entry_index.value() * byte_stride(); | |||||
| buffer()->Write(byte_pos, value, byte_stride()); | |||||
| } | |||||
| // Same as GeometryAttribute::GetValue(), but using point id as the input. | // Same as GeometryAttribute::GetValue(), but using point id as the input. | ||||
| // Mapping to attribute value index is performed automatically. | // Mapping to attribute value index is performed automatically. | ||||
| void GetMappedValue(PointIndex point_index, void *out_data) const { | void GetMappedValue(PointIndex point_index, void *out_data) const { | ||||
| return GetValue(mapped_index(point_index), out_data); | return GetValue(mapped_index(point_index), out_data); | ||||
| } | } | ||||
| #ifdef DRACO_ATTRIBUTE_VALUES_DEDUPLICATION_SUPPORTED | #ifdef DRACO_ATTRIBUTE_VALUES_DEDUPLICATION_SUPPORTED | ||||
| // Deduplicate |in_att| values into |this| attribute. |in_att| can be equal | // Deduplicate |in_att| values into |this| attribute. |in_att| can be equal | ||||
| ▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
| // Hash functor for the PointAttribute class. | // Hash functor for the PointAttribute class. | ||||
| struct PointAttributeHasher { | struct PointAttributeHasher { | ||||
| size_t operator()(const PointAttribute &attribute) const { | size_t operator()(const PointAttribute &attribute) const { | ||||
| GeometryAttributeHasher base_hasher; | GeometryAttributeHasher base_hasher; | ||||
| size_t hash = base_hasher(attribute); | size_t hash = base_hasher(attribute); | ||||
| hash = HashCombine(attribute.identity_mapping_, hash); | hash = HashCombine(attribute.identity_mapping_, hash); | ||||
| hash = HashCombine(attribute.num_unique_entries_, hash); | hash = HashCombine(attribute.num_unique_entries_, hash); | ||||
| hash = HashCombine(attribute.indices_map_.size(), hash); | hash = HashCombine(attribute.indices_map_.size(), hash); | ||||
| if (attribute.indices_map_.size() > 0) { | if (!attribute.indices_map_.empty()) { | ||||
| const uint64_t indices_hash = FingerprintString( | const uint64_t indices_hash = FingerprintString( | ||||
| reinterpret_cast<const char *>(attribute.indices_map_.data()), | reinterpret_cast<const char *>(attribute.indices_map_.data()), | ||||
| attribute.indices_map_.size()); | attribute.indices_map_.size()); | ||||
| hash = HashCombine(indices_hash, hash); | hash = HashCombine(indices_hash, hash); | ||||
| } | } | ||||
| if (attribute.attribute_buffer_ != nullptr) { | if (attribute.attribute_buffer_ != nullptr) { | ||||
| const uint64_t buffer_hash = FingerprintString( | const uint64_t buffer_hash = FingerprintString( | ||||
| reinterpret_cast<const char *>(attribute.attribute_buffer_->data()), | reinterpret_cast<const char *>(attribute.attribute_buffer_->data()), | ||||
| Show All 10 Lines | |||||