Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/attributes/geometry_attribute.h
- This file was moved from extern/draco/dracoenc/src/draco/attributes/geometry_attribute.h.
| Show First 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | public: | ||||
| // T is the attribute data type. | // T is the attribute data type. | ||||
| // att_components_t is the number of attribute components. | // att_components_t is the number of attribute components. | ||||
| template <typename T, int att_components_t> | template <typename T, int att_components_t> | ||||
| bool GetValue(AttributeValueIndex att_index, | bool GetValue(AttributeValueIndex att_index, | ||||
| std::array<T, att_components_t> *out) const { | std::array<T, att_components_t> *out) const { | ||||
| // Byte address of the attribute index. | // Byte address of the attribute index. | ||||
| const int64_t byte_pos = byte_offset_ + byte_stride_ * att_index.value(); | const int64_t byte_pos = byte_offset_ + byte_stride_ * att_index.value(); | ||||
| // Check we are not reading past end of data. | // Check we are not reading past end of data. | ||||
| if (byte_pos + sizeof(*out) > buffer_->data_size()) | if (byte_pos + sizeof(*out) > buffer_->data_size()) { | ||||
| return false; | return false; | ||||
| } | |||||
| buffer_->Read(byte_pos, &((*out)[0]), sizeof(*out)); | buffer_->Read(byte_pos, &((*out)[0]), sizeof(*out)); | ||||
| return true; | return true; | ||||
| } | } | ||||
| // Returns the byte position of the attribute entry in the data buffer. | // Returns the byte position of the attribute entry in the data buffer. | ||||
| inline int64_t GetBytePos(AttributeValueIndex att_index) const { | inline int64_t GetBytePos(AttributeValueIndex att_index) const { | ||||
| return byte_offset_ + byte_stride_ * att_index.value(); | return byte_offset_ + byte_stride_ * att_index.value(); | ||||
| } | } | ||||
| Show All 9 Lines | public: | ||||
| // Fills out_data with the raw value of the requested attribute entry. | // Fills out_data with the raw value of the requested attribute entry. | ||||
| // out_data must be at least byte_stride_ long. | // out_data must be at least byte_stride_ long. | ||||
| void GetValue(AttributeValueIndex att_index, void *out_data) const { | void GetValue(AttributeValueIndex att_index, void *out_data) const { | ||||
| const int64_t byte_pos = byte_offset_ + byte_stride_ * att_index.value(); | const int64_t byte_pos = byte_offset_ + byte_stride_ * att_index.value(); | ||||
| buffer_->Read(byte_pos, out_data, byte_stride_); | buffer_->Read(byte_pos, out_data, byte_stride_); | ||||
| } | } | ||||
| // 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()); | |||||
| } | |||||
| // DEPRECATED: Use | // DEPRECATED: Use | ||||
| // ConvertValue(AttributeValueIndex att_id, | // ConvertValue(AttributeValueIndex att_id, | ||||
| // int out_num_components, | // int out_num_components, | ||||
| // OutT *out_val); | // OutT *out_val); | ||||
| // | // | ||||
| // Function for conversion of a attribute to a specific output format. | // Function for conversion of a attribute to a specific output format. | ||||
| // OutT is the desired data type of the attribute. | // OutT is the desired data type of the attribute. | ||||
| // out_att_components_t is the number of components of the output format. | // out_att_components_t is the number of components of the output format. | ||||
| // Returns false when the conversion failed. | // Returns false when the conversion failed. | ||||
| template <typename OutT, int out_att_components_t> | template <typename OutT, int out_att_components_t> | ||||
| bool ConvertValue(AttributeValueIndex att_id, OutT *out_val) const { | bool ConvertValue(AttributeValueIndex att_id, OutT *out_val) const { | ||||
| return ConvertValue(att_id, out_att_components_t, out_val); | return ConvertValue(att_id, out_att_components_t, out_val); | ||||
| } | } | ||||
| // Function for conversion of a attribute to a specific output format. | // Function for conversion of a attribute to a specific output format. | ||||
| // |out_val| needs to be able to store |out_num_components| values. | // |out_val| needs to be able to store |out_num_components| values. | ||||
| // OutT is the desired data type of the attribute. | // OutT is the desired data type of the attribute. | ||||
| // Returns false when the conversion failed. | // Returns false when the conversion failed. | ||||
| template <typename OutT> | template <typename OutT> | ||||
| bool ConvertValue(AttributeValueIndex att_id, int8_t out_num_components, | bool ConvertValue(AttributeValueIndex att_id, int8_t out_num_components, | ||||
| OutT *out_val) const { | OutT *out_val) const { | ||||
| if (out_val == nullptr) | if (out_val == nullptr) { | ||||
| return false; | return false; | ||||
| } | |||||
| switch (data_type_) { | switch (data_type_) { | ||||
| case DT_INT8: | case DT_INT8: | ||||
| return ConvertTypedValue<int8_t, OutT>(att_id, out_num_components, | return ConvertTypedValue<int8_t, OutT>(att_id, out_num_components, | ||||
| out_val); | out_val); | ||||
| case DT_UINT8: | case DT_UINT8: | ||||
| return ConvertTypedValue<uint8_t, OutT>(att_id, out_num_components, | return ConvertTypedValue<uint8_t, OutT>(att_id, out_num_components, | ||||
| out_val); | out_val); | ||||
| case DT_INT16: | case DT_INT16: | ||||
| Show All 34 Lines | public: | ||||
| // entry. | // entry. | ||||
| // OutT is the desired data type of the attribute. | // OutT is the desired data type of the attribute. | ||||
| // Returns false when the conversion failed. | // Returns false when the conversion failed. | ||||
| template <typename OutT> | template <typename OutT> | ||||
| bool ConvertValue(AttributeValueIndex att_index, OutT *out_value) const { | bool ConvertValue(AttributeValueIndex att_index, OutT *out_value) const { | ||||
| return ConvertValue<OutT>(att_index, num_components_, out_value); | return ConvertValue<OutT>(att_index, num_components_, out_value); | ||||
| } | } | ||||
| // Utility function. Returns |attribute_type| as std::string. | |||||
| static std::string TypeToString(Type attribute_type) { | |||||
| switch (attribute_type) { | |||||
| case INVALID: | |||||
| return "INVALID"; | |||||
| case POSITION: | |||||
| return "POSITION"; | |||||
| case NORMAL: | |||||
| return "NORMAL"; | |||||
| case COLOR: | |||||
| return "COLOR"; | |||||
| case TEX_COORD: | |||||
| return "TEX_COORD"; | |||||
| case GENERIC: | |||||
| return "GENERIC"; | |||||
| default: | |||||
| return "UNKNOWN"; | |||||
| } | |||||
| } | |||||
| bool operator==(const GeometryAttribute &va) const; | bool operator==(const GeometryAttribute &va) const; | ||||
| // Returns the type of the attribute indicating the nature of the attribute. | // Returns the type of the attribute indicating the nature of the attribute. | ||||
| Type attribute_type() const { return attribute_type_; } | Type attribute_type() const { return attribute_type_; } | ||||
| void set_attribute_type(Type type) { attribute_type_ = type; } | void set_attribute_type(Type type) { attribute_type_ = type; } | ||||
| // Returns the data type that is stored in the attribute. | // Returns the data type that is stored in the attribute. | ||||
| DataType data_type() const { return data_type_; } | DataType data_type() const { return data_type_; } | ||||
| // Returns the number of components that are stored for each entry. | // Returns the number of components that are stored for each entry. | ||||
| ▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | |||||
| // Hashing support | // Hashing support | ||||
| // Function object for using Attribute as a hash key. | // Function object for using Attribute as a hash key. | ||||
| struct GeometryAttributeHasher { | struct GeometryAttributeHasher { | ||||
| size_t operator()(const GeometryAttribute &va) const { | size_t operator()(const GeometryAttribute &va) const { | ||||
| size_t hash = HashCombine(va.buffer_descriptor_.buffer_id, | size_t hash = HashCombine(va.buffer_descriptor_.buffer_id, | ||||
| va.buffer_descriptor_.buffer_update_count); | va.buffer_descriptor_.buffer_update_count); | ||||
| hash = HashCombine(va.num_components_, hash); | hash = HashCombine(va.num_components_, hash); | ||||
| hash = HashCombine((int8_t)va.data_type_, hash); | hash = HashCombine(static_cast<int8_t>(va.data_type_), hash); | ||||
| hash = HashCombine((int8_t)va.attribute_type_, hash); | hash = HashCombine(static_cast<int8_t>(va.attribute_type_), hash); | ||||
| hash = HashCombine(va.byte_stride_, hash); | hash = HashCombine(va.byte_stride_, hash); | ||||
| return HashCombine(va.byte_offset_, hash); | return HashCombine(va.byte_offset_, hash); | ||||
| } | } | ||||
| }; | }; | ||||
| // Function object for using GeometryAttribute::Type as a hash key. | // Function object for using GeometryAttribute::Type as a hash key. | ||||
| struct GeometryAttributeTypeHasher { | struct GeometryAttributeTypeHasher { | ||||
| size_t operator()(const GeometryAttribute::Type &at) const { | size_t operator()(const GeometryAttribute::Type &at) const { | ||||
| return static_cast<size_t>(at); | return static_cast<size_t>(at); | ||||
| } | } | ||||
| }; | }; | ||||
| } // namespace draco | } // namespace draco | ||||
| #endif // DRACO_ATTRIBUTES_GEOMETRY_ATTRIBUTE_H_ | #endif // DRACO_ATTRIBUTES_GEOMETRY_ATTRIBUTE_H_ | ||||