Differential D9642 Diff 31357 extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_decoder.h
Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_decoder.h
- This file was moved from extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_traversal_decoder.h.
| Show All 9 Lines | |||||
| // distributed under the License is distributed on an "AS IS" BASIS, | // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // 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_COMPRESSION_MESH_MESH_EDGEBREAKER_TRAVERSAL_DECODER_H_ | #ifndef DRACO_COMPRESSION_MESH_MESH_EDGEBREAKER_TRAVERSAL_DECODER_H_ | ||||
| #define DRACO_COMPRESSION_MESH_MESH_EDGEBREAKER_TRAVERSAL_DECODER_H_ | #define DRACO_COMPRESSION_MESH_MESH_EDGEBREAKER_TRAVERSAL_DECODER_H_ | ||||
| #include "draco/draco_features.h" | |||||
| #include "draco/compression/bit_coders/rans_bit_decoder.h" | #include "draco/compression/bit_coders/rans_bit_decoder.h" | ||||
| #include "draco/compression/mesh/mesh_edgebreaker_decoder.h" | #include "draco/compression/mesh/mesh_edgebreaker_decoder.h" | ||||
| #include "draco/compression/mesh/mesh_edgebreaker_decoder_impl_interface.h" | #include "draco/compression/mesh/mesh_edgebreaker_decoder_impl_interface.h" | ||||
| #include "draco/compression/mesh/mesh_edgebreaker_shared.h" | #include "draco/compression/mesh/mesh_edgebreaker_shared.h" | ||||
| #include "draco/draco_features.h" | |||||
| namespace draco { | namespace draco { | ||||
| typedef RAnsBitDecoder BinaryDecoder; | typedef RAnsBitDecoder BinaryDecoder; | ||||
| // Default implementation of the edgebreaker traversal decoder that reads the | // Default implementation of the edgebreaker traversal decoder that reads the | ||||
| // traversal data directly from a buffer. | // traversal data directly from a buffer. | ||||
| class MeshEdgebreakerTraversalDecoder { | class MeshEdgebreakerTraversalDecoder { | ||||
| Show All 23 Lines | public: | ||||
| void SetNumAttributeData(int num_data) { num_attribute_data_ = num_data; } | void SetNumAttributeData(int num_data) { num_attribute_data_ = num_data; } | ||||
| // Called before the traversal decoding is started. | // Called before the traversal decoding is started. | ||||
| // Returns a buffer decoder that points to data that was encoded after the | // Returns a buffer decoder that points to data that was encoded after the | ||||
| // traversal. | // traversal. | ||||
| bool Start(DecoderBuffer *out_buffer) { | bool Start(DecoderBuffer *out_buffer) { | ||||
| // Decode symbols from the main buffer decoder and face configurations from | // Decode symbols from the main buffer decoder and face configurations from | ||||
| // the start_face_buffer decoder. | // the start_face_buffer decoder. | ||||
| if (!DecodeTraversalSymbols()) | if (!DecodeTraversalSymbols()) { | ||||
| return false; | return false; | ||||
| } | |||||
| if (!DecodeStartFaces()) | if (!DecodeStartFaces()) { | ||||
| return false; | return false; | ||||
| } | |||||
| if (!DecodeAttributeSeams()) | if (!DecodeAttributeSeams()) { | ||||
| return false; | return false; | ||||
| } | |||||
| *out_buffer = buffer_; | *out_buffer = buffer_; | ||||
| return true; | return true; | ||||
| } | } | ||||
| // Returns the configuration of a new initial face. | // Returns the configuration of a new initial face. | ||||
| inline bool DecodeStartFaceConfiguration() { | inline bool DecodeStartFaceConfiguration() { | ||||
| uint32_t face_configuration; | uint32_t face_configuration; | ||||
| #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED | #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED | ||||
| Show All 34 Lines | #endif | ||||
| // |attribute| is used to mark the id of the non-position attribute (in range | // |attribute| is used to mark the id of the non-position attribute (in range | ||||
| // of <0, num_attributes - 1>). | // of <0, num_attributes - 1>). | ||||
| inline bool DecodeAttributeSeam(int attribute) { | inline bool DecodeAttributeSeam(int attribute) { | ||||
| return attribute_connectivity_decoders_[attribute].DecodeNextBit(); | return attribute_connectivity_decoders_[attribute].DecodeNextBit(); | ||||
| } | } | ||||
| // Called when the traversal is finished. | // Called when the traversal is finished. | ||||
| void Done() { | void Done() { | ||||
| if (symbol_buffer_.bit_decoder_active()) | if (symbol_buffer_.bit_decoder_active()) { | ||||
| symbol_buffer_.EndBitDecoding(); | symbol_buffer_.EndBitDecoding(); | ||||
| } | |||||
| #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED | #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED | ||||
| if (buffer_.bitstream_version() < DRACO_BITSTREAM_VERSION(2, 2)) { | if (buffer_.bitstream_version() < DRACO_BITSTREAM_VERSION(2, 2)) { | ||||
| start_face_buffer_.EndBitDecoding(); | start_face_buffer_.EndBitDecoding(); | ||||
| } else | } else | ||||
| #endif | #endif | ||||
| { | { | ||||
| start_face_decoder_.EndDecoding(); | start_face_decoder_.EndDecoding(); | ||||
| } | } | ||||
| } | } | ||||
| protected: | protected: | ||||
| DecoderBuffer *buffer() { return &buffer_; } | DecoderBuffer *buffer() { return &buffer_; } | ||||
| bool DecodeTraversalSymbols() { | bool DecodeTraversalSymbols() { | ||||
| uint64_t traversal_size; | uint64_t traversal_size; | ||||
| symbol_buffer_ = buffer_; | symbol_buffer_ = buffer_; | ||||
| if (!symbol_buffer_.StartBitDecoding(true, &traversal_size)) | if (!symbol_buffer_.StartBitDecoding(true, &traversal_size)) { | ||||
| return false; | return false; | ||||
| } | |||||
| buffer_ = symbol_buffer_; | buffer_ = symbol_buffer_; | ||||
| if (traversal_size > static_cast<uint64_t>(buffer_.remaining_size())) | if (traversal_size > static_cast<uint64_t>(buffer_.remaining_size())) { | ||||
| return false; | return false; | ||||
| } | |||||
| buffer_.Advance(traversal_size); | buffer_.Advance(traversal_size); | ||||
| return true; | return true; | ||||
| } | } | ||||
| bool DecodeStartFaces() { | bool DecodeStartFaces() { | ||||
| // Create a decoder that is set to the end of the encoded traversal data. | // Create a decoder that is set to the end of the encoded traversal data. | ||||
| #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED | #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED | ||||
| if (buffer_.bitstream_version() < DRACO_BITSTREAM_VERSION(2, 2)) { | if (buffer_.bitstream_version() < DRACO_BITSTREAM_VERSION(2, 2)) { | ||||
| start_face_buffer_ = buffer_; | start_face_buffer_ = buffer_; | ||||
| uint64_t traversal_size; | uint64_t traversal_size; | ||||
| if (!start_face_buffer_.StartBitDecoding(true, &traversal_size)) | if (!start_face_buffer_.StartBitDecoding(true, &traversal_size)) { | ||||
| return false; | return false; | ||||
| } | |||||
| buffer_ = start_face_buffer_; | buffer_ = start_face_buffer_; | ||||
| if (traversal_size > static_cast<uint64_t>(buffer_.remaining_size())) | if (traversal_size > static_cast<uint64_t>(buffer_.remaining_size())) { | ||||
| return false; | return false; | ||||
| } | |||||
| buffer_.Advance(traversal_size); | buffer_.Advance(traversal_size); | ||||
| return true; | return true; | ||||
| } | } | ||||
| #endif | #endif | ||||
| return start_face_decoder_.StartDecoding(&buffer_); | return start_face_decoder_.StartDecoding(&buffer_); | ||||
| } | } | ||||
| bool DecodeAttributeSeams() { | bool DecodeAttributeSeams() { | ||||
| // Prepare attribute decoding. | // Prepare attribute decoding. | ||||
| if (num_attribute_data_ > 0) { | if (num_attribute_data_ > 0) { | ||||
| attribute_connectivity_decoders_ = std::unique_ptr<BinaryDecoder[]>( | attribute_connectivity_decoders_ = std::unique_ptr<BinaryDecoder[]>( | ||||
| new BinaryDecoder[num_attribute_data_]); | new BinaryDecoder[num_attribute_data_]); | ||||
| for (int i = 0; i < num_attribute_data_; ++i) { | for (int i = 0; i < num_attribute_data_; ++i) { | ||||
| if (!attribute_connectivity_decoders_[i].StartDecoding(&buffer_)) | if (!attribute_connectivity_decoders_[i].StartDecoding(&buffer_)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| return true; | return true; | ||||
| } | } | ||||
| private: | private: | ||||
| // Buffer that contains the encoded data. | // Buffer that contains the encoded data. | ||||
| DecoderBuffer buffer_; | DecoderBuffer buffer_; | ||||
| DecoderBuffer symbol_buffer_; | DecoderBuffer symbol_buffer_; | ||||
| BinaryDecoder start_face_decoder_; | BinaryDecoder start_face_decoder_; | ||||
| Show All 9 Lines | |||||