Differential D9642 Diff 31697 extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_decoder.h
Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_decoder.h
- This file was moved from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_decoder.h.
| Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | public: | ||||
| bool DecodePredictionData(DecoderBuffer *buffer) override; | bool DecodePredictionData(DecoderBuffer *buffer) override; | ||||
| PredictionSchemeMethod GetPredictionMethod() const override { | PredictionSchemeMethod GetPredictionMethod() const override { | ||||
| return MESH_PREDICTION_TEX_COORDS_PORTABLE; | return MESH_PREDICTION_TEX_COORDS_PORTABLE; | ||||
| } | } | ||||
| bool IsInitialized() const override { | bool IsInitialized() const override { | ||||
| if (!predictor_.IsInitialized()) | if (!predictor_.IsInitialized()) { | ||||
| return false; | return false; | ||||
| if (!this->mesh_data().IsInitialized()) | } | ||||
| if (!this->mesh_data().IsInitialized()) { | |||||
| return false; | return false; | ||||
| } | |||||
| return true; | return true; | ||||
| } | } | ||||
| int GetNumParentAttributes() const override { return 1; } | int GetNumParentAttributes() const override { return 1; } | ||||
| GeometryAttribute::Type GetParentAttributeType(int i) const override { | GeometryAttribute::Type GetParentAttributeType(int i) const override { | ||||
| DRACO_DCHECK_EQ(i, 0); | DRACO_DCHECK_EQ(i, 0); | ||||
| (void)i; | (void)i; | ||||
| return GeometryAttribute::POSITION; | return GeometryAttribute::POSITION; | ||||
| } | } | ||||
| bool SetParentAttribute(const PointAttribute *att) override { | bool SetParentAttribute(const PointAttribute *att) override { | ||||
| if (!att || att->attribute_type() != GeometryAttribute::POSITION) | if (!att || att->attribute_type() != GeometryAttribute::POSITION) { | ||||
| return false; // Invalid attribute type. | return false; // Invalid attribute type. | ||||
| if (att->num_components() != 3) | } | ||||
| if (att->num_components() != 3) { | |||||
| return false; // Currently works only for 3 component positions. | return false; // Currently works only for 3 component positions. | ||||
| } | |||||
| predictor_.SetPositionAttribute(*att); | predictor_.SetPositionAttribute(*att); | ||||
| return true; | return true; | ||||
| } | } | ||||
| private: | private: | ||||
| MeshPredictionSchemeTexCoordsPortablePredictor<DataTypeT, MeshDataT> | MeshPredictionSchemeTexCoordsPortablePredictor<DataTypeT, MeshDataT> | ||||
| predictor_; | predictor_; | ||||
| }; | }; | ||||
| template <typename DataTypeT, class TransformT, class MeshDataT> | template <typename DataTypeT, class TransformT, class MeshDataT> | ||||
| bool MeshPredictionSchemeTexCoordsPortableDecoder< | bool MeshPredictionSchemeTexCoordsPortableDecoder< | ||||
| DataTypeT, TransformT, | DataTypeT, TransformT, | ||||
| MeshDataT>::ComputeOriginalValues(const CorrType *in_corr, | MeshDataT>::ComputeOriginalValues(const CorrType *in_corr, | ||||
| DataTypeT *out_data, int /* size */, | DataTypeT *out_data, int /* size */, | ||||
| int num_components, | int num_components, | ||||
| const PointIndex *entry_to_point_id_map) { | const PointIndex *entry_to_point_id_map) { | ||||
| if (num_components != MeshPredictionSchemeTexCoordsPortablePredictor< | |||||
| DataTypeT, MeshDataT>::kNumComponents) { | |||||
| return false; | |||||
| } | |||||
| predictor_.SetEntryToPointIdMap(entry_to_point_id_map); | predictor_.SetEntryToPointIdMap(entry_to_point_id_map); | ||||
| this->transform().Init(num_components); | this->transform().Init(num_components); | ||||
| const int corner_map_size = | const int corner_map_size = | ||||
| static_cast<int>(this->mesh_data().data_to_corner_map()->size()); | static_cast<int>(this->mesh_data().data_to_corner_map()->size()); | ||||
| for (int p = 0; p < corner_map_size; ++p) { | for (int p = 0; p < corner_map_size; ++p) { | ||||
| const CornerIndex corner_id = this->mesh_data().data_to_corner_map()->at(p); | const CornerIndex corner_id = this->mesh_data().data_to_corner_map()->at(p); | ||||
| if (!predictor_.template ComputePredictedValue<false>(corner_id, out_data, | if (!predictor_.template ComputePredictedValue<false>(corner_id, out_data, | ||||
| p)) | p)) { | ||||
| return false; | return false; | ||||
| } | |||||
| const int dst_offset = p * num_components; | const int dst_offset = p * num_components; | ||||
| this->transform().ComputeOriginalValue(predictor_.predicted_value(), | this->transform().ComputeOriginalValue(predictor_.predicted_value(), | ||||
| in_corr + dst_offset, | in_corr + dst_offset, | ||||
| out_data + dst_offset); | out_data + dst_offset); | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| template <typename DataTypeT, class TransformT, class MeshDataT> | template <typename DataTypeT, class TransformT, class MeshDataT> | ||||
| bool MeshPredictionSchemeTexCoordsPortableDecoder< | bool MeshPredictionSchemeTexCoordsPortableDecoder< | ||||
| DataTypeT, TransformT, MeshDataT>::DecodePredictionData(DecoderBuffer | DataTypeT, TransformT, MeshDataT>::DecodePredictionData(DecoderBuffer | ||||
| *buffer) { | *buffer) { | ||||
| // Decode the delta coded orientations. | // Decode the delta coded orientations. | ||||
| int32_t num_orientations = 0; | int32_t num_orientations = 0; | ||||
| if (!buffer->Decode(&num_orientations) || num_orientations < 0) | if (!buffer->Decode(&num_orientations) || num_orientations < 0) { | ||||
| return false; | return false; | ||||
| } | |||||
| predictor_.ResizeOrientations(num_orientations); | predictor_.ResizeOrientations(num_orientations); | ||||
| bool last_orientation = true; | bool last_orientation = true; | ||||
| RAnsBitDecoder decoder; | RAnsBitDecoder decoder; | ||||
| if (!decoder.StartDecoding(buffer)) | if (!decoder.StartDecoding(buffer)) { | ||||
| return false; | return false; | ||||
| } | |||||
| for (int i = 0; i < num_orientations; ++i) { | for (int i = 0; i < num_orientations; ++i) { | ||||
| if (!decoder.DecodeNextBit()) | if (!decoder.DecodeNextBit()) { | ||||
| last_orientation = !last_orientation; | last_orientation = !last_orientation; | ||||
| } | |||||
| predictor_.set_orientation(i, last_orientation); | predictor_.set_orientation(i, last_orientation); | ||||
| } | } | ||||
| decoder.EndDecoding(); | decoder.EndDecoding(); | ||||
| return MeshPredictionSchemeDecoder<DataTypeT, TransformT, | return MeshPredictionSchemeDecoder<DataTypeT, TransformT, | ||||
| MeshDataT>::DecodePredictionData(buffer); | MeshDataT>::DecodePredictionData(buffer); | ||||
| } | } | ||||
| } // namespace draco | } // namespace draco | ||||
| #endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_PORTABLE_DECODER_H_ | #endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_PORTABLE_DECODER_H_ | ||||