Differential D9642 Diff 31697 extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_predictor.h
Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_predictor.h
- This file was moved from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_predictor.h.
| Show All 10 Lines | |||||
| // 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_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_PORTABLE_PREDICTOR_H_ | #ifndef DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_PORTABLE_PREDICTOR_H_ | ||||
| #define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_PORTABLE_PREDICTOR_H_ | #define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_PORTABLE_PREDICTOR_H_ | ||||
| #include <math.h> | #include <math.h> | ||||
| #include "draco/attributes/point_attribute.h" | #include "draco/attributes/point_attribute.h" | ||||
| #include "draco/core/math_utils.h" | #include "draco/core/math_utils.h" | ||||
| #include "draco/core/vector_d.h" | #include "draco/core/vector_d.h" | ||||
| #include "draco/mesh/corner_table.h" | #include "draco/mesh/corner_table.h" | ||||
| namespace draco { | namespace draco { | ||||
| // Predictor functionality used for portable UV prediction by both encoder and | // Predictor functionality used for portable UV prediction by both encoder and | ||||
| // decoder. | // decoder. | ||||
| template <typename DataTypeT, class MeshDataT> | template <typename DataTypeT, class MeshDataT> | ||||
| class MeshPredictionSchemeTexCoordsPortablePredictor { | class MeshPredictionSchemeTexCoordsPortablePredictor { | ||||
| public: | public: | ||||
| static constexpr int kNumComponents = 2; | |||||
| explicit MeshPredictionSchemeTexCoordsPortablePredictor(const MeshDataT &md) | explicit MeshPredictionSchemeTexCoordsPortablePredictor(const MeshDataT &md) | ||||
| : pos_attribute_(nullptr), | : pos_attribute_(nullptr), | ||||
| entry_to_point_id_map_(nullptr), | entry_to_point_id_map_(nullptr), | ||||
| mesh_data_(md) {} | mesh_data_(md) {} | ||||
| void SetPositionAttribute(const PointAttribute &position_attribute) { | void SetPositionAttribute(const PointAttribute &position_attribute) { | ||||
| pos_attribute_ = &position_attribute; | pos_attribute_ = &position_attribute; | ||||
| } | } | ||||
| void SetEntryToPointIdMap(const PointIndex *map) { | void SetEntryToPointIdMap(const PointIndex *map) { | ||||
| Show All 27 Lines | public: | ||||
| size_t num_orientations() const { return orientations_.size(); } | size_t num_orientations() const { return orientations_.size(); } | ||||
| void ResizeOrientations(int num_orientations) { | void ResizeOrientations(int num_orientations) { | ||||
| orientations_.resize(num_orientations); | orientations_.resize(num_orientations); | ||||
| } | } | ||||
| private: | private: | ||||
| const PointAttribute *pos_attribute_; | const PointAttribute *pos_attribute_; | ||||
| const PointIndex *entry_to_point_id_map_; | const PointIndex *entry_to_point_id_map_; | ||||
| static constexpr int kNumComponents = 2; | |||||
| DataTypeT predicted_value_[kNumComponents]; | DataTypeT predicted_value_[kNumComponents]; | ||||
| // Encoded / decoded array of UV flips. | // Encoded / decoded array of UV flips. | ||||
| // TODO(ostava): We should remove this and replace this with in-place encoding | // TODO(ostava): We should remove this and replace this with in-place encoding | ||||
| // and decoding to avoid unnecessary copy. | // and decoding to avoid unnecessary copy. | ||||
| std::vector<bool> orientations_; | std::vector<bool> orientations_; | ||||
| MeshDataT mesh_data_; | MeshDataT mesh_data_; | ||||
| }; | }; | ||||
| ▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | if (pn_norm2_squared != 0) { | ||||
| predicted_uv = predicted_uv_0; | predicted_uv = predicted_uv_0; | ||||
| orientations_.push_back(true); | orientations_.push_back(true); | ||||
| } else { | } else { | ||||
| predicted_uv = predicted_uv_1; | predicted_uv = predicted_uv_1; | ||||
| orientations_.push_back(false); | orientations_.push_back(false); | ||||
| } | } | ||||
| } else { | } else { | ||||
| // When decoding the data, we already know which orientation to use. | // When decoding the data, we already know which orientation to use. | ||||
| if (orientations_.empty()) | if (orientations_.empty()) { | ||||
| return false; | return false; | ||||
| } | |||||
| const bool orientation = orientations_.back(); | const bool orientation = orientations_.back(); | ||||
| orientations_.pop_back(); | orientations_.pop_back(); | ||||
| if (orientation) | if (orientation) { | ||||
| predicted_uv = (x_uv + cx_uv) / pn_norm2_squared; | predicted_uv = (x_uv + cx_uv) / pn_norm2_squared; | ||||
| else | } else { | ||||
| predicted_uv = (x_uv - cx_uv) / pn_norm2_squared; | predicted_uv = (x_uv - cx_uv) / pn_norm2_squared; | ||||
| } | } | ||||
| } | |||||
| predicted_value_[0] = static_cast<int>(predicted_uv[0]); | predicted_value_[0] = static_cast<int>(predicted_uv[0]); | ||||
| predicted_value_[1] = static_cast<int>(predicted_uv[1]); | predicted_value_[1] = static_cast<int>(predicted_uv[1]); | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| // Else we don't have available textures on both corners or the position data | // Else we don't have available textures on both corners or the position data | ||||
| // is invalid. For such cases we can't use positions for predicting the uv | // is invalid. For such cases we can't use positions for predicting the uv | ||||
| // value and we resort to delta coding. | // value and we resort to delta coding. | ||||
| Show All 30 Lines | |||||