dracox 0.0.1__cp39-cp39-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. bin/draco_decoder.exe +0 -0
  2. bin/draco_encoder.exe +0 -0
  3. dracox/__init__.py +252 -0
  4. dracox/dracox_ext.cp39-win_amd64.pyd +0 -0
  5. dracox-0.0.1.dist-info/METADATA +14 -0
  6. dracox-0.0.1.dist-info/RECORD +214 -0
  7. dracox-0.0.1.dist-info/WHEEL +5 -0
  8. include/draco/animation/keyframe_animation.h +107 -0
  9. include/draco/animation/keyframe_animation_decoder.h +34 -0
  10. include/draco/animation/keyframe_animation_encoder.h +39 -0
  11. include/draco/attributes/attribute_octahedron_transform.h +81 -0
  12. include/draco/attributes/attribute_quantization_transform.h +102 -0
  13. include/draco/attributes/attribute_transform.h +76 -0
  14. include/draco/attributes/attribute_transform_data.h +71 -0
  15. include/draco/attributes/attribute_transform_type.h +30 -0
  16. include/draco/attributes/geometry_attribute.h +541 -0
  17. include/draco/attributes/geometry_indices.h +54 -0
  18. include/draco/attributes/point_attribute.h +196 -0
  19. include/draco/compression/attributes/attributes_decoder.h +97 -0
  20. include/draco/compression/attributes/attributes_decoder_interface.h +62 -0
  21. include/draco/compression/attributes/attributes_encoder.h +154 -0
  22. include/draco/compression/attributes/kd_tree_attributes_decoder.h +50 -0
  23. include/draco/compression/attributes/kd_tree_attributes_encoder.h +51 -0
  24. include/draco/compression/attributes/kd_tree_attributes_shared.h +28 -0
  25. include/draco/compression/attributes/linear_sequencer.h +51 -0
  26. include/draco/compression/attributes/mesh_attribute_indices_encoding_data.h +58 -0
  27. include/draco/compression/attributes/normal_compression_utils.h +372 -0
  28. include/draco/compression/attributes/point_d_vector.h +288 -0
  29. include/draco/compression/attributes/points_sequencer.h +63 -0
  30. include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_decoder.h +236 -0
  31. include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_encoder.h +413 -0
  32. include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_shared.h +34 -0
  33. include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_data.h +72 -0
  34. include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_decoder.h +46 -0
  35. include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_encoder.h +46 -0
  36. include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_decoder.h +176 -0
  37. include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_encoder.h +180 -0
  38. include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_area.h +117 -0
  39. include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_base.h +96 -0
  40. include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_decoder.h +128 -0
  41. include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_encoder.h +133 -0
  42. include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_encoder.h +111 -0
  43. include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_shared.h +78 -0
  44. include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_decoder.h +372 -0
  45. include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_encoder.h +318 -0
  46. include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_decoder.h +143 -0
  47. include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_encoder.h +136 -0
  48. include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_predictor.h +282 -0
  49. include/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder.h +90 -0
  50. include/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_factory.h +194 -0
  51. include/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_interface.h +53 -0
  52. include/draco/compression/attributes/prediction_schemes/prediction_scheme_decoding_transform.h +65 -0
  53. include/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_decoder.h +65 -0
  54. include/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_encoder.h +69 -0
  55. include/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder.h +90 -0
  56. include/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_factory.h +134 -0
  57. include/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_interface.h +55 -0
  58. include/draco/compression/attributes/prediction_schemes/prediction_scheme_encoding_transform.h +77 -0
  59. include/draco/compression/attributes/prediction_schemes/prediction_scheme_factory.h +85 -0
  60. include/draco/compression/attributes/prediction_schemes/prediction_scheme_interface.h +60 -0
  61. include/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_decoding_transform.h +118 -0
  62. include/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h +116 -0
  63. include/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_transform_base.h +102 -0
  64. include/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_decoding_transform.h +115 -0
  65. include/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_encoding_transform.h +105 -0
  66. include/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_transform_base.h +90 -0
  67. include/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_decoding_transform.h +88 -0
  68. include/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_encoding_transform.h +81 -0
  69. include/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_transform_base.h +120 -0
  70. include/draco/compression/attributes/sequential_attribute_decoder.h +86 -0
  71. include/draco/compression/attributes/sequential_attribute_decoders_controller.h +61 -0
  72. include/draco/compression/attributes/sequential_attribute_encoder.h +134 -0
  73. include/draco/compression/attributes/sequential_attribute_encoders_controller.h +115 -0
  74. include/draco/compression/attributes/sequential_integer_attribute_decoder.h +76 -0
  75. include/draco/compression/attributes/sequential_integer_attribute_encoder.h +67 -0
  76. include/draco/compression/attributes/sequential_normal_attribute_decoder.h +83 -0
  77. include/draco/compression/attributes/sequential_normal_attribute_encoder.h +82 -0
  78. include/draco/compression/attributes/sequential_quantization_attribute_decoder.h +52 -0
  79. include/draco/compression/attributes/sequential_quantization_attribute_encoder.h +52 -0
  80. include/draco/compression/bit_coders/adaptive_rans_bit_coding_shared.h +43 -0
  81. include/draco/compression/bit_coders/adaptive_rans_bit_decoder.h +54 -0
  82. include/draco/compression/bit_coders/adaptive_rans_bit_encoder.h +61 -0
  83. include/draco/compression/bit_coders/direct_bit_decoder.h +89 -0
  84. include/draco/compression/bit_coders/direct_bit_encoder.h +89 -0
  85. include/draco/compression/bit_coders/folded_integer_bit_decoder.h +77 -0
  86. include/draco/compression/bit_coders/folded_integer_bit_encoder.h +82 -0
  87. include/draco/compression/bit_coders/rans_bit_decoder.h +55 -0
  88. include/draco/compression/bit_coders/rans_bit_encoder.h +57 -0
  89. include/draco/compression/bit_coders/symbol_bit_decoder.h +36 -0
  90. include/draco/compression/bit_coders/symbol_bit_encoder.h +36 -0
  91. include/draco/compression/config/compression_shared.h +155 -0
  92. include/draco/compression/config/decoder_options.h +34 -0
  93. include/draco/compression/config/draco_options.h +249 -0
  94. include/draco/compression/config/encoder_options.h +101 -0
  95. include/draco/compression/config/encoding_features.h +39 -0
  96. include/draco/compression/decode.h +80 -0
  97. include/draco/compression/draco_compression_options.h +141 -0
  98. include/draco/compression/encode.h +139 -0
  99. include/draco/compression/encode_base.h +131 -0
  100. include/draco/compression/entropy/ans.h +526 -0
  101. include/draco/compression/entropy/rans_symbol_coding.h +53 -0
  102. include/draco/compression/entropy/rans_symbol_decoder.h +171 -0
  103. include/draco/compression/entropy/rans_symbol_encoder.h +290 -0
  104. include/draco/compression/entropy/shannon_entropy.h +110 -0
  105. include/draco/compression/entropy/symbol_decoding.h +29 -0
  106. include/draco/compression/entropy/symbol_encoding.h +47 -0
  107. include/draco/compression/expert_encode.h +160 -0
  108. include/draco/compression/mesh/mesh_decoder.h +68 -0
  109. include/draco/compression/mesh/mesh_edgebreaker_decoder.h +54 -0
  110. include/draco/compression/mesh/mesh_edgebreaker_decoder_impl.h +228 -0
  111. include/draco/compression/mesh/mesh_edgebreaker_decoder_impl_interface.h +47 -0
  112. include/draco/compression/mesh/mesh_edgebreaker_encoder.h +73 -0
  113. include/draco/compression/mesh/mesh_edgebreaker_encoder_impl.h +209 -0
  114. include/draco/compression/mesh/mesh_edgebreaker_encoder_impl_interface.h +57 -0
  115. include/draco/compression/mesh/mesh_edgebreaker_shared.h +129 -0
  116. include/draco/compression/mesh/mesh_edgebreaker_traversal_decoder.h +201 -0
  117. include/draco/compression/mesh/mesh_edgebreaker_traversal_encoder.h +139 -0
  118. include/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_decoder.h +134 -0
  119. include/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_encoder.h +172 -0
  120. include/draco/compression/mesh/mesh_edgebreaker_traversal_valence_decoder.h +219 -0
  121. include/draco/compression/mesh/mesh_edgebreaker_traversal_valence_encoder.h +226 -0
  122. include/draco/compression/mesh/mesh_encoder.h +84 -0
  123. include/draco/compression/mesh/mesh_sequential_decoder.h +39 -0
  124. include/draco/compression/mesh/mesh_sequential_encoder.h +56 -0
  125. include/draco/compression/mesh/traverser/depth_first_traverser.h +172 -0
  126. include/draco/compression/mesh/traverser/max_prediction_degree_traverser.h +226 -0
  127. include/draco/compression/mesh/traverser/mesh_attribute_indices_encoding_observer.h +76 -0
  128. include/draco/compression/mesh/traverser/mesh_traversal_sequencer.h +113 -0
  129. include/draco/compression/mesh/traverser/traverser_base.h +87 -0
  130. include/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.h +369 -0
  131. include/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.h +372 -0
  132. include/draco/compression/point_cloud/algorithms/float_points_tree_decoder.h +141 -0
  133. include/draco/compression/point_cloud/algorithms/float_points_tree_encoder.h +126 -0
  134. include/draco/compression/point_cloud/algorithms/point_cloud_compression_method.h +34 -0
  135. include/draco/compression/point_cloud/algorithms/point_cloud_types.h +76 -0
  136. include/draco/compression/point_cloud/algorithms/quantize_points_3.h +84 -0
  137. include/draco/compression/point_cloud/algorithms/queuing_policy.h +75 -0
  138. include/draco/compression/point_cloud/point_cloud_decoder.h +118 -0
  139. include/draco/compression/point_cloud/point_cloud_encoder.h +158 -0
  140. include/draco/compression/point_cloud/point_cloud_kd_tree_decoder.h +31 -0
  141. include/draco/compression/point_cloud/point_cloud_kd_tree_encoder.h +45 -0
  142. include/draco/compression/point_cloud/point_cloud_sequential_decoder.h +33 -0
  143. include/draco/compression/point_cloud/point_cloud_sequential_encoder.h +43 -0
  144. include/draco/core/bit_utils.h +127 -0
  145. include/draco/core/bounding_box.h +77 -0
  146. include/draco/core/constants.h +6 -0
  147. include/draco/core/cycle_timer.h +51 -0
  148. include/draco/core/data_buffer.h +82 -0
  149. include/draco/core/decoder_buffer.h +216 -0
  150. include/draco/core/divide.h +42 -0
  151. include/draco/core/draco_index_type.h +184 -0
  152. include/draco/core/draco_index_type_vector.h +90 -0
  153. include/draco/core/draco_types.h +52 -0
  154. include/draco/core/draco_version.h +25 -0
  155. include/draco/core/encoder_buffer.h +152 -0
  156. include/draco/core/hash_utils.h +64 -0
  157. include/draco/core/macros.h +124 -0
  158. include/draco/core/math_utils.h +79 -0
  159. include/draco/core/options.h +151 -0
  160. include/draco/core/quantization_utils.h +82 -0
  161. include/draco/core/status.h +83 -0
  162. include/draco/core/status_or.h +81 -0
  163. include/draco/core/varint_decoding.h +81 -0
  164. include/draco/core/varint_encoding.h +61 -0
  165. include/draco/core/vector_d.h +355 -0
  166. include/draco/draco_features.h +25 -0
  167. include/draco/io/file_reader_factory.h +34 -0
  168. include/draco/io/file_reader_interface.h +32 -0
  169. include/draco/io/file_utils.h +86 -0
  170. include/draco/io/file_writer_factory.h +34 -0
  171. include/draco/io/file_writer_interface.h +26 -0
  172. include/draco/io/file_writer_utils.h +38 -0
  173. include/draco/io/mesh_io.h +107 -0
  174. include/draco/io/obj_decoder.h +147 -0
  175. include/draco/io/obj_encoder.h +107 -0
  176. include/draco/io/parser_utils.h +66 -0
  177. include/draco/io/ply_decoder.h +69 -0
  178. include/draco/io/ply_encoder.h +54 -0
  179. include/draco/io/ply_property_reader.h +96 -0
  180. include/draco/io/ply_property_writer.h +94 -0
  181. include/draco/io/ply_reader.h +155 -0
  182. include/draco/io/point_cloud_io.h +89 -0
  183. include/draco/io/stdio_file_reader.h +48 -0
  184. include/draco/io/stdio_file_writer.h +42 -0
  185. include/draco/io/stl_decoder.h +38 -0
  186. include/draco/io/stl_encoder.h +52 -0
  187. include/draco/mesh/corner_table.h +397 -0
  188. include/draco/mesh/corner_table_iterators.h +309 -0
  189. include/draco/mesh/mesh.h +378 -0
  190. include/draco/mesh/mesh_are_equivalent.h +71 -0
  191. include/draco/mesh/mesh_attribute_corner_table.h +202 -0
  192. include/draco/mesh/mesh_cleanup.h +61 -0
  193. include/draco/mesh/mesh_features.h +93 -0
  194. include/draco/mesh/mesh_indices.h +37 -0
  195. include/draco/mesh/mesh_misc_functions.h +105 -0
  196. include/draco/mesh/mesh_stripifier.h +258 -0
  197. include/draco/mesh/triangle_soup_mesh_builder.h +134 -0
  198. include/draco/mesh/valence_cache.h +142 -0
  199. include/draco/metadata/geometry_metadata.h +142 -0
  200. include/draco/metadata/metadata.h +209 -0
  201. include/draco/metadata/metadata_decoder.h +42 -0
  202. include/draco/metadata/metadata_encoder.h +41 -0
  203. include/draco/metadata/property_attribute.h +107 -0
  204. include/draco/metadata/property_table.h +222 -0
  205. include/draco/metadata/structural_metadata.h +78 -0
  206. include/draco/metadata/structural_metadata_schema.h +118 -0
  207. include/draco/point_cloud/point_cloud.h +289 -0
  208. include/draco/point_cloud/point_cloud_builder.h +101 -0
  209. lib/draco.lib +0 -0
  210. lib/pkgconfig/draco.pc +6 -0
  211. share/cmake/draco/draco-config-version.cmake +43 -0
  212. share/cmake/draco/draco-config.cmake +27 -0
  213. share/cmake/draco/draco-targets-release.cmake +19 -0
  214. share/cmake/draco/draco-targets.cmake +107 -0
@@ -0,0 +1,372 @@
1
+ // Copyright 2016 The Draco Authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
16
+ #ifndef DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_DECODER_H_
17
+ #define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_DECODER_H_
18
+
19
+ #include <math.h>
20
+
21
+ #include "draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_decoder.h"
22
+ #include "draco/compression/bit_coders/rans_bit_decoder.h"
23
+ #include "draco/core/varint_decoding.h"
24
+ #include "draco/core/vector_d.h"
25
+ #include "draco/draco_features.h"
26
+ #include "draco/mesh/corner_table.h"
27
+
28
+ namespace draco {
29
+
30
+ // Decoder for predictions of UV coordinates encoded by our specialized texture
31
+ // coordinate predictor. See the corresponding encoder for more details. Note
32
+ // that this predictor is not portable and should not be used anymore. See
33
+ // MeshPredictionSchemeTexCoordsPortableEncoder/Decoder for a portable version
34
+ // of this prediction scheme.
35
+ template <typename DataTypeT, class TransformT, class MeshDataT>
36
+ class MeshPredictionSchemeTexCoordsDecoder
37
+ : public MeshPredictionSchemeDecoder<DataTypeT, TransformT, MeshDataT> {
38
+ public:
39
+ using CorrType = typename MeshPredictionSchemeDecoder<DataTypeT, TransformT,
40
+ MeshDataT>::CorrType;
41
+ MeshPredictionSchemeTexCoordsDecoder(const PointAttribute *attribute,
42
+ const TransformT &transform,
43
+ const MeshDataT &mesh_data, int version)
44
+ : MeshPredictionSchemeDecoder<DataTypeT, TransformT, MeshDataT>(
45
+ attribute, transform, mesh_data),
46
+ pos_attribute_(nullptr),
47
+ entry_to_point_id_map_(nullptr),
48
+ num_components_(0),
49
+ version_(version) {}
50
+
51
+ bool ComputeOriginalValues(const CorrType *in_corr, DataTypeT *out_data,
52
+ int size, int num_components,
53
+ const PointIndex *entry_to_point_id_map) override;
54
+
55
+ bool DecodePredictionData(DecoderBuffer *buffer) override;
56
+
57
+ PredictionSchemeMethod GetPredictionMethod() const override {
58
+ return MESH_PREDICTION_TEX_COORDS_DEPRECATED;
59
+ }
60
+
61
+ bool IsInitialized() const override {
62
+ if (pos_attribute_ == nullptr) {
63
+ return false;
64
+ }
65
+ if (!this->mesh_data().IsInitialized()) {
66
+ return false;
67
+ }
68
+ return true;
69
+ }
70
+
71
+ int GetNumParentAttributes() const override { return 1; }
72
+
73
+ GeometryAttribute::Type GetParentAttributeType(int i) const override {
74
+ DRACO_DCHECK_EQ(i, 0);
75
+ (void)i;
76
+ return GeometryAttribute::POSITION;
77
+ }
78
+
79
+ bool SetParentAttribute(const PointAttribute *att) override {
80
+ if (att == nullptr) {
81
+ return false;
82
+ }
83
+ if (att->attribute_type() != GeometryAttribute::POSITION) {
84
+ return false; // Invalid attribute type.
85
+ }
86
+ if (att->num_components() != 3) {
87
+ return false; // Currently works only for 3 component positions.
88
+ }
89
+ pos_attribute_ = att;
90
+ return true;
91
+ }
92
+
93
+ protected:
94
+ Vector3f GetPositionForEntryId(int entry_id) const {
95
+ const PointIndex point_id = entry_to_point_id_map_[entry_id];
96
+ Vector3f pos;
97
+ pos_attribute_->ConvertValue(pos_attribute_->mapped_index(point_id),
98
+ &pos[0]);
99
+ return pos;
100
+ }
101
+
102
+ Vector2f GetTexCoordForEntryId(int entry_id, const DataTypeT *data) const {
103
+ const int data_offset = entry_id * num_components_;
104
+ return Vector2f(static_cast<float>(data[data_offset]),
105
+ static_cast<float>(data[data_offset + 1]));
106
+ }
107
+
108
+ bool ComputePredictedValue(CornerIndex corner_id, const DataTypeT *data,
109
+ int data_id);
110
+
111
+ private:
112
+ const PointAttribute *pos_attribute_;
113
+ const PointIndex *entry_to_point_id_map_;
114
+ std::unique_ptr<DataTypeT[]> predicted_value_;
115
+ int num_components_;
116
+ // Encoded / decoded array of UV flips.
117
+ std::vector<bool> orientations_;
118
+ int version_;
119
+ };
120
+
121
+ template <typename DataTypeT, class TransformT, class MeshDataT>
122
+ bool MeshPredictionSchemeTexCoordsDecoder<DataTypeT, TransformT, MeshDataT>::
123
+ ComputeOriginalValues(const CorrType *in_corr, DataTypeT *out_data,
124
+ int /* size */, int num_components,
125
+ const PointIndex *entry_to_point_id_map) {
126
+ if (num_components != 2) {
127
+ // Corrupt/malformed input. Two output components are req'd.
128
+ return false;
129
+ }
130
+ num_components_ = num_components;
131
+ entry_to_point_id_map_ = entry_to_point_id_map;
132
+ predicted_value_ =
133
+ std::unique_ptr<DataTypeT[]>(new DataTypeT[num_components]);
134
+ this->transform().Init(num_components);
135
+
136
+ const int corner_map_size =
137
+ static_cast<int>(this->mesh_data().data_to_corner_map()->size());
138
+ for (int p = 0; p < corner_map_size; ++p) {
139
+ const CornerIndex corner_id = this->mesh_data().data_to_corner_map()->at(p);
140
+ if (!ComputePredictedValue(corner_id, out_data, p)) {
141
+ return false;
142
+ }
143
+
144
+ const int dst_offset = p * num_components;
145
+ this->transform().ComputeOriginalValue(
146
+ predicted_value_.get(), in_corr + dst_offset, out_data + dst_offset);
147
+ }
148
+ return true;
149
+ }
150
+
151
+ template <typename DataTypeT, class TransformT, class MeshDataT>
152
+ bool MeshPredictionSchemeTexCoordsDecoder<DataTypeT, TransformT, MeshDataT>::
153
+ DecodePredictionData(DecoderBuffer *buffer) {
154
+ // Decode the delta coded orientations.
155
+ uint32_t num_orientations = 0;
156
+ if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 2)) {
157
+ if (!buffer->Decode(&num_orientations)) {
158
+ return false;
159
+ }
160
+ } else {
161
+ if (!DecodeVarint(&num_orientations, buffer)) {
162
+ return false;
163
+ }
164
+ }
165
+ if (num_orientations == 0) {
166
+ return false;
167
+ }
168
+ if (num_orientations > this->mesh_data().corner_table()->num_corners()) {
169
+ // We can't have more orientations than the maximum number of decoded
170
+ // values.
171
+ return false;
172
+ }
173
+ orientations_.resize(num_orientations);
174
+ bool last_orientation = true;
175
+ RAnsBitDecoder decoder;
176
+ if (!decoder.StartDecoding(buffer)) {
177
+ return false;
178
+ }
179
+ for (uint32_t i = 0; i < num_orientations; ++i) {
180
+ if (!decoder.DecodeNextBit()) {
181
+ last_orientation = !last_orientation;
182
+ }
183
+ orientations_[i] = last_orientation;
184
+ }
185
+ decoder.EndDecoding();
186
+ return MeshPredictionSchemeDecoder<DataTypeT, TransformT,
187
+ MeshDataT>::DecodePredictionData(buffer);
188
+ }
189
+
190
+ template <typename DataTypeT, class TransformT, class MeshDataT>
191
+ bool MeshPredictionSchemeTexCoordsDecoder<DataTypeT, TransformT, MeshDataT>::
192
+ ComputePredictedValue(CornerIndex corner_id, const DataTypeT *data,
193
+ int data_id) {
194
+ // Compute the predicted UV coordinate from the positions on all corners
195
+ // of the processed triangle. For the best prediction, the UV coordinates
196
+ // on the next/previous corners need to be already encoded/decoded.
197
+ const CornerIndex next_corner_id =
198
+ this->mesh_data().corner_table()->Next(corner_id);
199
+ const CornerIndex prev_corner_id =
200
+ this->mesh_data().corner_table()->Previous(corner_id);
201
+ // Get the encoded data ids from the next and previous corners.
202
+ // The data id is the encoding order of the UV coordinates.
203
+ int next_data_id, prev_data_id;
204
+
205
+ int next_vert_id, prev_vert_id;
206
+ next_vert_id =
207
+ this->mesh_data().corner_table()->Vertex(next_corner_id).value();
208
+ prev_vert_id =
209
+ this->mesh_data().corner_table()->Vertex(prev_corner_id).value();
210
+
211
+ next_data_id = this->mesh_data().vertex_to_data_map()->at(next_vert_id);
212
+ prev_data_id = this->mesh_data().vertex_to_data_map()->at(prev_vert_id);
213
+
214
+ if (prev_data_id < data_id && next_data_id < data_id) {
215
+ // Both other corners have available UV coordinates for prediction.
216
+ const Vector2f n_uv = GetTexCoordForEntryId(next_data_id, data);
217
+ const Vector2f p_uv = GetTexCoordForEntryId(prev_data_id, data);
218
+ if (p_uv == n_uv) {
219
+ // We cannot do a reliable prediction on degenerated UV triangles.
220
+ // Technically floats > INT_MAX are undefined, but compilers will
221
+ // convert those values to INT_MIN. We are being explicit here for asan.
222
+ for (const int i : {0, 1}) {
223
+ if (std::isnan(p_uv[i]) || static_cast<double>(p_uv[i]) > INT_MAX ||
224
+ static_cast<double>(p_uv[i]) < INT_MIN) {
225
+ predicted_value_[i] = INT_MIN;
226
+ } else {
227
+ predicted_value_[i] = static_cast<int>(p_uv[i]);
228
+ }
229
+ }
230
+ return true;
231
+ }
232
+
233
+ // Get positions at all corners.
234
+ const Vector3f tip_pos = GetPositionForEntryId(data_id);
235
+ const Vector3f next_pos = GetPositionForEntryId(next_data_id);
236
+ const Vector3f prev_pos = GetPositionForEntryId(prev_data_id);
237
+ // Use the positions of the above triangle to predict the texture coordinate
238
+ // on the tip corner C.
239
+ // Convert the triangle into a new coordinate system defined by orthogonal
240
+ // bases vectors S, T, where S is vector prev_pos - next_pos and T is an
241
+ // perpendicular vector to S in the same plane as vector the
242
+ // tip_pos - next_pos.
243
+ // The transformed triangle in the new coordinate system is then going to
244
+ // be represented as:
245
+ //
246
+ // 1 ^
247
+ // |
248
+ // |
249
+ // | C
250
+ // | / \
251
+ // | / \
252
+ // |/ \
253
+ // N--------------P
254
+ // 0 1
255
+ //
256
+ // Where next_pos point (N) is at position (0, 0), prev_pos point (P) is
257
+ // at (1, 0). Our goal is to compute the position of the tip_pos point (C)
258
+ // in this new coordinate space (s, t).
259
+ //
260
+ const Vector3f pn = prev_pos - next_pos;
261
+ const Vector3f cn = tip_pos - next_pos;
262
+ const float pn_norm2_squared = pn.SquaredNorm();
263
+ // Coordinate s of the tip corner C is simply the dot product of the
264
+ // normalized vectors |pn| and |cn| (normalized by the length of |pn|).
265
+ // Since both of these vectors are normalized, we don't need to perform the
266
+ // normalization explicitly and instead we can just use the squared norm
267
+ // of |pn| as a denominator of the resulting dot product of non normalized
268
+ // vectors.
269
+ float s, t;
270
+ // |pn_norm2_squared| can be exactly 0 when the next_pos and prev_pos are
271
+ // the same positions (e.g. because they were quantized to the same
272
+ // location).
273
+ if (version_ < DRACO_BITSTREAM_VERSION(1, 2) || pn_norm2_squared > 0) {
274
+ s = pn.Dot(cn) / pn_norm2_squared;
275
+ // To get the coordinate t, we can use formula:
276
+ // t = |C-N - (P-N) * s| / |P-N|
277
+ // Do not use std::sqrt to avoid changes in the bitstream.
278
+ t = sqrt((cn - pn * s).SquaredNorm() / pn_norm2_squared);
279
+ } else {
280
+ s = 0;
281
+ t = 0;
282
+ }
283
+
284
+ // Now we need to transform the point (s, t) to the texture coordinate space
285
+ // UV. We know the UV coordinates on points N and P (N_UV and P_UV). Lets
286
+ // denote P_UV - N_UV = PN_UV. PN_UV is then 2 dimensional vector that can
287
+ // be used to define transformation from the normalized coordinate system
288
+ // to the texture coordinate system using a 3x3 affine matrix M:
289
+ //
290
+ // M = | PN_UV[0] -PN_UV[1] N_UV[0] |
291
+ // | PN_UV[1] PN_UV[0] N_UV[1] |
292
+ // | 0 0 1 |
293
+ //
294
+ // The predicted point C_UV in the texture space is then equal to
295
+ // C_UV = M * (s, t, 1). Because the triangle in UV space may be flipped
296
+ // around the PN_UV axis, we also need to consider point C_UV' = M * (s, -t)
297
+ // as the prediction.
298
+ const Vector2f pn_uv = p_uv - n_uv;
299
+ const float pnus = pn_uv[0] * s + n_uv[0];
300
+ const float pnut = pn_uv[0] * t;
301
+ const float pnvs = pn_uv[1] * s + n_uv[1];
302
+ const float pnvt = pn_uv[1] * t;
303
+ Vector2f predicted_uv;
304
+ if (orientations_.empty()) {
305
+ return false;
306
+ }
307
+
308
+ // When decoding the data, we already know which orientation to use.
309
+ const bool orientation = orientations_.back();
310
+ orientations_.pop_back();
311
+ if (orientation) {
312
+ predicted_uv = Vector2f(pnus - pnvt, pnvs + pnut);
313
+ } else {
314
+ predicted_uv = Vector2f(pnus + pnvt, pnvs - pnut);
315
+ }
316
+ if (std::is_integral<DataTypeT>::value) {
317
+ // Round the predicted value for integer types.
318
+ // Technically floats > INT_MAX are undefined, but compilers will
319
+ // convert those values to INT_MIN. We are being explicit here for asan.
320
+ const double u = floor(predicted_uv[0] + 0.5);
321
+ if (std::isnan(u) || u > INT_MAX || u < INT_MIN) {
322
+ predicted_value_[0] = INT_MIN;
323
+ } else {
324
+ predicted_value_[0] = static_cast<int>(u);
325
+ }
326
+ const double v = floor(predicted_uv[1] + 0.5);
327
+ if (std::isnan(v) || v > INT_MAX || v < INT_MIN) {
328
+ predicted_value_[1] = INT_MIN;
329
+ } else {
330
+ predicted_value_[1] = static_cast<int>(v);
331
+ }
332
+ } else {
333
+ predicted_value_[0] = static_cast<int>(predicted_uv[0]);
334
+ predicted_value_[1] = static_cast<int>(predicted_uv[1]);
335
+ }
336
+
337
+ return true;
338
+ }
339
+ // Else we don't have available textures on both corners. For such case we
340
+ // can't use positions for predicting the uv value and we resort to delta
341
+ // coding.
342
+ int data_offset = 0;
343
+ if (prev_data_id < data_id) {
344
+ // Use the value on the previous corner as the prediction.
345
+ data_offset = prev_data_id * num_components_;
346
+ }
347
+ if (next_data_id < data_id) {
348
+ // Use the value on the next corner as the prediction.
349
+ data_offset = next_data_id * num_components_;
350
+ } else {
351
+ // None of the other corners have a valid value. Use the last encoded value
352
+ // as the prediction if possible.
353
+ if (data_id > 0) {
354
+ data_offset = (data_id - 1) * num_components_;
355
+ } else {
356
+ // We are encoding the first value. Predict 0.
357
+ for (int i = 0; i < num_components_; ++i) {
358
+ predicted_value_[i] = 0;
359
+ }
360
+ return true;
361
+ }
362
+ }
363
+ for (int i = 0; i < num_components_; ++i) {
364
+ predicted_value_[i] = data[data_offset + i];
365
+ }
366
+ return true;
367
+ }
368
+
369
+ } // namespace draco
370
+
371
+ #endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_DECODER_H_
372
+ #endif
@@ -0,0 +1,318 @@
1
+ // Copyright 2016 The Draco Authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ #ifndef DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_ENCODER_H_
16
+ #define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_ENCODER_H_
17
+
18
+ #include <math.h>
19
+
20
+ #include "draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_encoder.h"
21
+ #include "draco/compression/bit_coders/rans_bit_encoder.h"
22
+ #include "draco/core/varint_encoding.h"
23
+ #include "draco/core/vector_d.h"
24
+ #include "draco/mesh/corner_table.h"
25
+
26
+ namespace draco {
27
+
28
+ // Prediction scheme designed for predicting texture coordinates from known
29
+ // spatial position of vertices. For good parametrization, the ratios between
30
+ // triangle edge lengths should be about the same in both the spatial and UV
31
+ // coordinate spaces, which makes the positions a good predictor for the UV
32
+ // coordinates.
33
+ template <typename DataTypeT, class TransformT, class MeshDataT>
34
+ class MeshPredictionSchemeTexCoordsEncoder
35
+ : public MeshPredictionSchemeEncoder<DataTypeT, TransformT, MeshDataT> {
36
+ public:
37
+ using CorrType = typename MeshPredictionSchemeEncoder<DataTypeT, TransformT,
38
+ MeshDataT>::CorrType;
39
+ MeshPredictionSchemeTexCoordsEncoder(const PointAttribute *attribute,
40
+ const TransformT &transform,
41
+ const MeshDataT &mesh_data)
42
+ : MeshPredictionSchemeEncoder<DataTypeT, TransformT, MeshDataT>(
43
+ attribute, transform, mesh_data),
44
+ pos_attribute_(nullptr),
45
+ entry_to_point_id_map_(nullptr),
46
+ num_components_(0) {}
47
+
48
+ bool ComputeCorrectionValues(
49
+ const DataTypeT *in_data, CorrType *out_corr, int size,
50
+ int num_components, const PointIndex *entry_to_point_id_map) override;
51
+
52
+ bool EncodePredictionData(EncoderBuffer *buffer) override;
53
+
54
+ PredictionSchemeMethod GetPredictionMethod() const override {
55
+ return MESH_PREDICTION_TEX_COORDS_DEPRECATED;
56
+ }
57
+
58
+ bool IsInitialized() const override {
59
+ if (pos_attribute_ == nullptr) {
60
+ return false;
61
+ }
62
+ if (!this->mesh_data().IsInitialized()) {
63
+ return false;
64
+ }
65
+ return true;
66
+ }
67
+
68
+ int GetNumParentAttributes() const override { return 1; }
69
+
70
+ GeometryAttribute::Type GetParentAttributeType(int i) const override {
71
+ DRACO_DCHECK_EQ(i, 0);
72
+ (void)i;
73
+ return GeometryAttribute::POSITION;
74
+ }
75
+
76
+ bool SetParentAttribute(const PointAttribute *att) override {
77
+ if (att->attribute_type() != GeometryAttribute::POSITION) {
78
+ return false; // Invalid attribute type.
79
+ }
80
+ if (att->num_components() != 3) {
81
+ return false; // Currently works only for 3 component positions.
82
+ }
83
+ pos_attribute_ = att;
84
+ return true;
85
+ }
86
+
87
+ protected:
88
+ Vector3f GetPositionForEntryId(int entry_id) const {
89
+ const PointIndex point_id = entry_to_point_id_map_[entry_id];
90
+ Vector3f pos;
91
+ pos_attribute_->ConvertValue(pos_attribute_->mapped_index(point_id),
92
+ &pos[0]);
93
+ return pos;
94
+ }
95
+
96
+ Vector2f GetTexCoordForEntryId(int entry_id, const DataTypeT *data) const {
97
+ const int data_offset = entry_id * num_components_;
98
+ return Vector2f(static_cast<float>(data[data_offset]),
99
+ static_cast<float>(data[data_offset + 1]));
100
+ }
101
+
102
+ void ComputePredictedValue(CornerIndex corner_id, const DataTypeT *data,
103
+ int data_id);
104
+
105
+ private:
106
+ const PointAttribute *pos_attribute_;
107
+ const PointIndex *entry_to_point_id_map_;
108
+ std::unique_ptr<DataTypeT[]> predicted_value_;
109
+ int num_components_;
110
+ // Encoded / decoded array of UV flips.
111
+ std::vector<bool> orientations_;
112
+ };
113
+
114
+ template <typename DataTypeT, class TransformT, class MeshDataT>
115
+ bool MeshPredictionSchemeTexCoordsEncoder<DataTypeT, TransformT, MeshDataT>::
116
+ ComputeCorrectionValues(const DataTypeT *in_data, CorrType *out_corr,
117
+ int size, int num_components,
118
+ const PointIndex *entry_to_point_id_map) {
119
+ num_components_ = num_components;
120
+ entry_to_point_id_map_ = entry_to_point_id_map;
121
+ predicted_value_ =
122
+ std::unique_ptr<DataTypeT[]>(new DataTypeT[num_components]);
123
+ this->transform().Init(in_data, size, num_components);
124
+ // We start processing from the end because this prediction uses data from
125
+ // previous entries that could be overwritten when an entry is processed.
126
+ for (int p =
127
+ static_cast<int>(this->mesh_data().data_to_corner_map()->size()) - 1;
128
+ p >= 0; --p) {
129
+ const CornerIndex corner_id = this->mesh_data().data_to_corner_map()->at(p);
130
+ ComputePredictedValue(corner_id, in_data, p);
131
+
132
+ const int dst_offset = p * num_components;
133
+ this->transform().ComputeCorrection(
134
+ in_data + dst_offset, predicted_value_.get(), out_corr + dst_offset);
135
+ }
136
+ return true;
137
+ }
138
+
139
+ template <typename DataTypeT, class TransformT, class MeshDataT>
140
+ bool MeshPredictionSchemeTexCoordsEncoder<DataTypeT, TransformT, MeshDataT>::
141
+ EncodePredictionData(EncoderBuffer *buffer) {
142
+ // Encode the delta-coded orientations using arithmetic coding.
143
+ const uint32_t num_orientations = static_cast<uint32_t>(orientations_.size());
144
+ EncodeVarint(num_orientations, buffer);
145
+ bool last_orientation = true;
146
+ RAnsBitEncoder encoder;
147
+ encoder.StartEncoding();
148
+ for (bool orientation : orientations_) {
149
+ encoder.EncodeBit(orientation == last_orientation);
150
+ last_orientation = orientation;
151
+ }
152
+ encoder.EndEncoding(buffer);
153
+ return MeshPredictionSchemeEncoder<DataTypeT, TransformT,
154
+ MeshDataT>::EncodePredictionData(buffer);
155
+ }
156
+
157
+ template <typename DataTypeT, class TransformT, class MeshDataT>
158
+ void MeshPredictionSchemeTexCoordsEncoder<DataTypeT, TransformT, MeshDataT>::
159
+ ComputePredictedValue(CornerIndex corner_id, const DataTypeT *data,
160
+ int data_id) {
161
+ // Compute the predicted UV coordinate from the positions on all corners
162
+ // of the processed triangle. For the best prediction, the UV coordinates
163
+ // on the next/previous corners need to be already encoded/decoded.
164
+ const CornerIndex next_corner_id =
165
+ this->mesh_data().corner_table()->Next(corner_id);
166
+ const CornerIndex prev_corner_id =
167
+ this->mesh_data().corner_table()->Previous(corner_id);
168
+ // Get the encoded data ids from the next and previous corners.
169
+ // The data id is the encoding order of the UV coordinates.
170
+ int next_data_id, prev_data_id;
171
+
172
+ int next_vert_id, prev_vert_id;
173
+ next_vert_id =
174
+ this->mesh_data().corner_table()->Vertex(next_corner_id).value();
175
+ prev_vert_id =
176
+ this->mesh_data().corner_table()->Vertex(prev_corner_id).value();
177
+
178
+ next_data_id = this->mesh_data().vertex_to_data_map()->at(next_vert_id);
179
+ prev_data_id = this->mesh_data().vertex_to_data_map()->at(prev_vert_id);
180
+
181
+ if (prev_data_id < data_id && next_data_id < data_id) {
182
+ // Both other corners have available UV coordinates for prediction.
183
+ const Vector2f n_uv = GetTexCoordForEntryId(next_data_id, data);
184
+ const Vector2f p_uv = GetTexCoordForEntryId(prev_data_id, data);
185
+ if (p_uv == n_uv) {
186
+ // We cannot do a reliable prediction on degenerated UV triangles.
187
+ predicted_value_[0] = static_cast<int>(p_uv[0]);
188
+ predicted_value_[1] = static_cast<int>(p_uv[1]);
189
+ return;
190
+ }
191
+
192
+ // Get positions at all corners.
193
+ const Vector3f tip_pos = GetPositionForEntryId(data_id);
194
+ const Vector3f next_pos = GetPositionForEntryId(next_data_id);
195
+ const Vector3f prev_pos = GetPositionForEntryId(prev_data_id);
196
+ // Use the positions of the above triangle to predict the texture coordinate
197
+ // on the tip corner C.
198
+ // Convert the triangle into a new coordinate system defined by orthogonal
199
+ // bases vectors S, T, where S is vector prev_pos - next_pos and T is an
200
+ // perpendicular vector to S in the same plane as vector the
201
+ // tip_pos - next_pos.
202
+ // The transformed triangle in the new coordinate system is then going to
203
+ // be represented as:
204
+ //
205
+ // 1 ^
206
+ // |
207
+ // |
208
+ // | C
209
+ // | / \
210
+ // | / \
211
+ // |/ \
212
+ // N--------------P
213
+ // 0 1
214
+ //
215
+ // Where next_pos point (N) is at position (0, 0), prev_pos point (P) is
216
+ // at (1, 0). Our goal is to compute the position of the tip_pos point (C)
217
+ // in this new coordinate space (s, t).
218
+ //
219
+ const Vector3f pn = prev_pos - next_pos;
220
+ const Vector3f cn = tip_pos - next_pos;
221
+ const float pn_norm2_squared = pn.SquaredNorm();
222
+ // Coordinate s of the tip corner C is simply the dot product of the
223
+ // normalized vectors |pn| and |cn| (normalized by the length of |pn|).
224
+ // Since both of these vectors are normalized, we don't need to perform the
225
+ // normalization explicitly and instead we can just use the squared norm
226
+ // of |pn| as a denominator of the resulting dot product of non normalized
227
+ // vectors.
228
+ float s, t;
229
+ // |pn_norm2_squared| can be exactly 0 when the next_pos and prev_pos are
230
+ // the same positions (e.g. because they were quantized to the same
231
+ // location).
232
+ if (pn_norm2_squared > 0) {
233
+ s = pn.Dot(cn) / pn_norm2_squared;
234
+ // To get the coordinate t, we can use formula:
235
+ // t = |C-N - (P-N) * s| / |P-N|
236
+ // Do not use std::sqrt to avoid changes in the bitstream.
237
+ t = sqrt((cn - pn * s).SquaredNorm() / pn_norm2_squared);
238
+ } else {
239
+ s = 0;
240
+ t = 0;
241
+ }
242
+
243
+ // Now we need to transform the point (s, t) to the texture coordinate space
244
+ // UV. We know the UV coordinates on points N and P (N_UV and P_UV). Lets
245
+ // denote P_UV - N_UV = PN_UV. PN_UV is then 2 dimensional vector that can
246
+ // be used to define transformation from the normalized coordinate system
247
+ // to the texture coordinate system using a 3x3 affine matrix M:
248
+ //
249
+ // M = | PN_UV[0] -PN_UV[1] N_UV[0] |
250
+ // | PN_UV[1] PN_UV[0] N_UV[1] |
251
+ // | 0 0 1 |
252
+ //
253
+ // The predicted point C_UV in the texture space is then equal to
254
+ // C_UV = M * (s, t, 1). Because the triangle in UV space may be flipped
255
+ // around the PN_UV axis, we also need to consider point C_UV' = M * (s, -t)
256
+ // as the prediction.
257
+ const Vector2f pn_uv = p_uv - n_uv;
258
+ const float pnus = pn_uv[0] * s + n_uv[0];
259
+ const float pnut = pn_uv[0] * t;
260
+ const float pnvs = pn_uv[1] * s + n_uv[1];
261
+ const float pnvt = pn_uv[1] * t;
262
+ Vector2f predicted_uv;
263
+
264
+ // When encoding compute both possible vectors and determine which one
265
+ // results in a better prediction.
266
+ const Vector2f predicted_uv_0(pnus - pnvt, pnvs + pnut);
267
+ const Vector2f predicted_uv_1(pnus + pnvt, pnvs - pnut);
268
+ const Vector2f c_uv = GetTexCoordForEntryId(data_id, data);
269
+ if ((c_uv - predicted_uv_0).SquaredNorm() <
270
+ (c_uv - predicted_uv_1).SquaredNorm()) {
271
+ predicted_uv = predicted_uv_0;
272
+ orientations_.push_back(true);
273
+ } else {
274
+ predicted_uv = predicted_uv_1;
275
+ orientations_.push_back(false);
276
+ }
277
+ if (std::is_integral<DataTypeT>::value) {
278
+ // Round the predicted value for integer types.
279
+ predicted_value_[0] = static_cast<int>(floor(predicted_uv[0] + 0.5));
280
+ predicted_value_[1] = static_cast<int>(floor(predicted_uv[1] + 0.5));
281
+ } else {
282
+ predicted_value_[0] = static_cast<int>(predicted_uv[0]);
283
+ predicted_value_[1] = static_cast<int>(predicted_uv[1]);
284
+ }
285
+ return;
286
+ }
287
+ // Else we don't have available textures on both corners. For such case we
288
+ // can't use positions for predicting the uv value and we resort to delta
289
+ // coding.
290
+ int data_offset = 0;
291
+ if (prev_data_id < data_id) {
292
+ // Use the value on the previous corner as the prediction.
293
+ data_offset = prev_data_id * num_components_;
294
+ }
295
+ if (next_data_id < data_id) {
296
+ // Use the value on the next corner as the prediction.
297
+ data_offset = next_data_id * num_components_;
298
+ } else {
299
+ // None of the other corners have a valid value. Use the last encoded value
300
+ // as the prediction if possible.
301
+ if (data_id > 0) {
302
+ data_offset = (data_id - 1) * num_components_;
303
+ } else {
304
+ // We are encoding the first value. Predict 0.
305
+ for (int i = 0; i < num_components_; ++i) {
306
+ predicted_value_[i] = 0;
307
+ }
308
+ return;
309
+ }
310
+ }
311
+ for (int i = 0; i < num_components_; ++i) {
312
+ predicted_value_[i] = data[data_offset + i];
313
+ }
314
+ }
315
+
316
+ } // namespace draco
317
+
318
+ #endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_H_