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.
- bin/draco_decoder.exe +0 -0
- bin/draco_encoder.exe +0 -0
- dracox/__init__.py +252 -0
- dracox/dracox_ext.cp39-win_amd64.pyd +0 -0
- dracox-0.0.1.dist-info/METADATA +14 -0
- dracox-0.0.1.dist-info/RECORD +214 -0
- dracox-0.0.1.dist-info/WHEEL +5 -0
- include/draco/animation/keyframe_animation.h +107 -0
- include/draco/animation/keyframe_animation_decoder.h +34 -0
- include/draco/animation/keyframe_animation_encoder.h +39 -0
- include/draco/attributes/attribute_octahedron_transform.h +81 -0
- include/draco/attributes/attribute_quantization_transform.h +102 -0
- include/draco/attributes/attribute_transform.h +76 -0
- include/draco/attributes/attribute_transform_data.h +71 -0
- include/draco/attributes/attribute_transform_type.h +30 -0
- include/draco/attributes/geometry_attribute.h +541 -0
- include/draco/attributes/geometry_indices.h +54 -0
- include/draco/attributes/point_attribute.h +196 -0
- include/draco/compression/attributes/attributes_decoder.h +97 -0
- include/draco/compression/attributes/attributes_decoder_interface.h +62 -0
- include/draco/compression/attributes/attributes_encoder.h +154 -0
- include/draco/compression/attributes/kd_tree_attributes_decoder.h +50 -0
- include/draco/compression/attributes/kd_tree_attributes_encoder.h +51 -0
- include/draco/compression/attributes/kd_tree_attributes_shared.h +28 -0
- include/draco/compression/attributes/linear_sequencer.h +51 -0
- include/draco/compression/attributes/mesh_attribute_indices_encoding_data.h +58 -0
- include/draco/compression/attributes/normal_compression_utils.h +372 -0
- include/draco/compression/attributes/point_d_vector.h +288 -0
- include/draco/compression/attributes/points_sequencer.h +63 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_decoder.h +236 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_encoder.h +413 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_shared.h +34 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_data.h +72 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_decoder.h +46 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_encoder.h +46 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_decoder.h +176 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_encoder.h +180 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_area.h +117 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_base.h +96 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_decoder.h +128 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_encoder.h +133 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_encoder.h +111 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_shared.h +78 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_decoder.h +372 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_encoder.h +318 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_decoder.h +143 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_encoder.h +136 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_predictor.h +282 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder.h +90 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_factory.h +194 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_interface.h +53 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_decoding_transform.h +65 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_decoder.h +65 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_encoder.h +69 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder.h +90 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_factory.h +134 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_interface.h +55 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_encoding_transform.h +77 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_factory.h +85 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_interface.h +60 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_decoding_transform.h +118 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h +116 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_transform_base.h +102 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_decoding_transform.h +115 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_encoding_transform.h +105 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_transform_base.h +90 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_decoding_transform.h +88 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_encoding_transform.h +81 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_transform_base.h +120 -0
- include/draco/compression/attributes/sequential_attribute_decoder.h +86 -0
- include/draco/compression/attributes/sequential_attribute_decoders_controller.h +61 -0
- include/draco/compression/attributes/sequential_attribute_encoder.h +134 -0
- include/draco/compression/attributes/sequential_attribute_encoders_controller.h +115 -0
- include/draco/compression/attributes/sequential_integer_attribute_decoder.h +76 -0
- include/draco/compression/attributes/sequential_integer_attribute_encoder.h +67 -0
- include/draco/compression/attributes/sequential_normal_attribute_decoder.h +83 -0
- include/draco/compression/attributes/sequential_normal_attribute_encoder.h +82 -0
- include/draco/compression/attributes/sequential_quantization_attribute_decoder.h +52 -0
- include/draco/compression/attributes/sequential_quantization_attribute_encoder.h +52 -0
- include/draco/compression/bit_coders/adaptive_rans_bit_coding_shared.h +43 -0
- include/draco/compression/bit_coders/adaptive_rans_bit_decoder.h +54 -0
- include/draco/compression/bit_coders/adaptive_rans_bit_encoder.h +61 -0
- include/draco/compression/bit_coders/direct_bit_decoder.h +89 -0
- include/draco/compression/bit_coders/direct_bit_encoder.h +89 -0
- include/draco/compression/bit_coders/folded_integer_bit_decoder.h +77 -0
- include/draco/compression/bit_coders/folded_integer_bit_encoder.h +82 -0
- include/draco/compression/bit_coders/rans_bit_decoder.h +55 -0
- include/draco/compression/bit_coders/rans_bit_encoder.h +57 -0
- include/draco/compression/bit_coders/symbol_bit_decoder.h +36 -0
- include/draco/compression/bit_coders/symbol_bit_encoder.h +36 -0
- include/draco/compression/config/compression_shared.h +155 -0
- include/draco/compression/config/decoder_options.h +34 -0
- include/draco/compression/config/draco_options.h +249 -0
- include/draco/compression/config/encoder_options.h +101 -0
- include/draco/compression/config/encoding_features.h +39 -0
- include/draco/compression/decode.h +80 -0
- include/draco/compression/draco_compression_options.h +141 -0
- include/draco/compression/encode.h +139 -0
- include/draco/compression/encode_base.h +131 -0
- include/draco/compression/entropy/ans.h +526 -0
- include/draco/compression/entropy/rans_symbol_coding.h +53 -0
- include/draco/compression/entropy/rans_symbol_decoder.h +171 -0
- include/draco/compression/entropy/rans_symbol_encoder.h +290 -0
- include/draco/compression/entropy/shannon_entropy.h +110 -0
- include/draco/compression/entropy/symbol_decoding.h +29 -0
- include/draco/compression/entropy/symbol_encoding.h +47 -0
- include/draco/compression/expert_encode.h +160 -0
- include/draco/compression/mesh/mesh_decoder.h +68 -0
- include/draco/compression/mesh/mesh_edgebreaker_decoder.h +54 -0
- include/draco/compression/mesh/mesh_edgebreaker_decoder_impl.h +228 -0
- include/draco/compression/mesh/mesh_edgebreaker_decoder_impl_interface.h +47 -0
- include/draco/compression/mesh/mesh_edgebreaker_encoder.h +73 -0
- include/draco/compression/mesh/mesh_edgebreaker_encoder_impl.h +209 -0
- include/draco/compression/mesh/mesh_edgebreaker_encoder_impl_interface.h +57 -0
- include/draco/compression/mesh/mesh_edgebreaker_shared.h +129 -0
- include/draco/compression/mesh/mesh_edgebreaker_traversal_decoder.h +201 -0
- include/draco/compression/mesh/mesh_edgebreaker_traversal_encoder.h +139 -0
- include/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_decoder.h +134 -0
- include/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_encoder.h +172 -0
- include/draco/compression/mesh/mesh_edgebreaker_traversal_valence_decoder.h +219 -0
- include/draco/compression/mesh/mesh_edgebreaker_traversal_valence_encoder.h +226 -0
- include/draco/compression/mesh/mesh_encoder.h +84 -0
- include/draco/compression/mesh/mesh_sequential_decoder.h +39 -0
- include/draco/compression/mesh/mesh_sequential_encoder.h +56 -0
- include/draco/compression/mesh/traverser/depth_first_traverser.h +172 -0
- include/draco/compression/mesh/traverser/max_prediction_degree_traverser.h +226 -0
- include/draco/compression/mesh/traverser/mesh_attribute_indices_encoding_observer.h +76 -0
- include/draco/compression/mesh/traverser/mesh_traversal_sequencer.h +113 -0
- include/draco/compression/mesh/traverser/traverser_base.h +87 -0
- include/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.h +369 -0
- include/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.h +372 -0
- include/draco/compression/point_cloud/algorithms/float_points_tree_decoder.h +141 -0
- include/draco/compression/point_cloud/algorithms/float_points_tree_encoder.h +126 -0
- include/draco/compression/point_cloud/algorithms/point_cloud_compression_method.h +34 -0
- include/draco/compression/point_cloud/algorithms/point_cloud_types.h +76 -0
- include/draco/compression/point_cloud/algorithms/quantize_points_3.h +84 -0
- include/draco/compression/point_cloud/algorithms/queuing_policy.h +75 -0
- include/draco/compression/point_cloud/point_cloud_decoder.h +118 -0
- include/draco/compression/point_cloud/point_cloud_encoder.h +158 -0
- include/draco/compression/point_cloud/point_cloud_kd_tree_decoder.h +31 -0
- include/draco/compression/point_cloud/point_cloud_kd_tree_encoder.h +45 -0
- include/draco/compression/point_cloud/point_cloud_sequential_decoder.h +33 -0
- include/draco/compression/point_cloud/point_cloud_sequential_encoder.h +43 -0
- include/draco/core/bit_utils.h +127 -0
- include/draco/core/bounding_box.h +77 -0
- include/draco/core/constants.h +6 -0
- include/draco/core/cycle_timer.h +51 -0
- include/draco/core/data_buffer.h +82 -0
- include/draco/core/decoder_buffer.h +216 -0
- include/draco/core/divide.h +42 -0
- include/draco/core/draco_index_type.h +184 -0
- include/draco/core/draco_index_type_vector.h +90 -0
- include/draco/core/draco_types.h +52 -0
- include/draco/core/draco_version.h +25 -0
- include/draco/core/encoder_buffer.h +152 -0
- include/draco/core/hash_utils.h +64 -0
- include/draco/core/macros.h +124 -0
- include/draco/core/math_utils.h +79 -0
- include/draco/core/options.h +151 -0
- include/draco/core/quantization_utils.h +82 -0
- include/draco/core/status.h +83 -0
- include/draco/core/status_or.h +81 -0
- include/draco/core/varint_decoding.h +81 -0
- include/draco/core/varint_encoding.h +61 -0
- include/draco/core/vector_d.h +355 -0
- include/draco/draco_features.h +25 -0
- include/draco/io/file_reader_factory.h +34 -0
- include/draco/io/file_reader_interface.h +32 -0
- include/draco/io/file_utils.h +86 -0
- include/draco/io/file_writer_factory.h +34 -0
- include/draco/io/file_writer_interface.h +26 -0
- include/draco/io/file_writer_utils.h +38 -0
- include/draco/io/mesh_io.h +107 -0
- include/draco/io/obj_decoder.h +147 -0
- include/draco/io/obj_encoder.h +107 -0
- include/draco/io/parser_utils.h +66 -0
- include/draco/io/ply_decoder.h +69 -0
- include/draco/io/ply_encoder.h +54 -0
- include/draco/io/ply_property_reader.h +96 -0
- include/draco/io/ply_property_writer.h +94 -0
- include/draco/io/ply_reader.h +155 -0
- include/draco/io/point_cloud_io.h +89 -0
- include/draco/io/stdio_file_reader.h +48 -0
- include/draco/io/stdio_file_writer.h +42 -0
- include/draco/io/stl_decoder.h +38 -0
- include/draco/io/stl_encoder.h +52 -0
- include/draco/mesh/corner_table.h +397 -0
- include/draco/mesh/corner_table_iterators.h +309 -0
- include/draco/mesh/mesh.h +378 -0
- include/draco/mesh/mesh_are_equivalent.h +71 -0
- include/draco/mesh/mesh_attribute_corner_table.h +202 -0
- include/draco/mesh/mesh_cleanup.h +61 -0
- include/draco/mesh/mesh_features.h +93 -0
- include/draco/mesh/mesh_indices.h +37 -0
- include/draco/mesh/mesh_misc_functions.h +105 -0
- include/draco/mesh/mesh_stripifier.h +258 -0
- include/draco/mesh/triangle_soup_mesh_builder.h +134 -0
- include/draco/mesh/valence_cache.h +142 -0
- include/draco/metadata/geometry_metadata.h +142 -0
- include/draco/metadata/metadata.h +209 -0
- include/draco/metadata/metadata_decoder.h +42 -0
- include/draco/metadata/metadata_encoder.h +41 -0
- include/draco/metadata/property_attribute.h +107 -0
- include/draco/metadata/property_table.h +222 -0
- include/draco/metadata/structural_metadata.h +78 -0
- include/draco/metadata/structural_metadata_schema.h +118 -0
- include/draco/point_cloud/point_cloud.h +289 -0
- include/draco/point_cloud/point_cloud_builder.h +101 -0
- lib/draco.lib +0 -0
- lib/pkgconfig/draco.pc +6 -0
- share/cmake/draco/draco-config-version.cmake +43 -0
- share/cmake/draco/draco-config.cmake +27 -0
- share/cmake/draco/draco-targets-release.cmake +19 -0
- share/cmake/draco/draco-targets.cmake +107 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// Copyright 2017 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_PORTABLE_DECODER_H_
|
|
16
|
+
#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_PORTABLE_DECODER_H_
|
|
17
|
+
|
|
18
|
+
#include "draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_decoder.h"
|
|
19
|
+
#include "draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_predictor.h"
|
|
20
|
+
#include "draco/compression/bit_coders/rans_bit_decoder.h"
|
|
21
|
+
|
|
22
|
+
namespace draco {
|
|
23
|
+
|
|
24
|
+
// Decoder for predictions of UV coordinates encoded by our specialized and
|
|
25
|
+
// portable texture coordinate predictor. See the corresponding encoder for more
|
|
26
|
+
// details.
|
|
27
|
+
template <typename DataTypeT, class TransformT, class MeshDataT>
|
|
28
|
+
class MeshPredictionSchemeTexCoordsPortableDecoder
|
|
29
|
+
: public MeshPredictionSchemeDecoder<DataTypeT, TransformT, MeshDataT> {
|
|
30
|
+
public:
|
|
31
|
+
using CorrType = typename MeshPredictionSchemeDecoder<DataTypeT, TransformT,
|
|
32
|
+
MeshDataT>::CorrType;
|
|
33
|
+
MeshPredictionSchemeTexCoordsPortableDecoder(const PointAttribute *attribute,
|
|
34
|
+
const TransformT &transform,
|
|
35
|
+
const MeshDataT &mesh_data)
|
|
36
|
+
: MeshPredictionSchemeDecoder<DataTypeT, TransformT, MeshDataT>(
|
|
37
|
+
attribute, transform, mesh_data),
|
|
38
|
+
predictor_(mesh_data) {}
|
|
39
|
+
|
|
40
|
+
bool ComputeOriginalValues(const CorrType *in_corr, DataTypeT *out_data,
|
|
41
|
+
int size, int num_components,
|
|
42
|
+
const PointIndex *entry_to_point_id_map) override;
|
|
43
|
+
|
|
44
|
+
bool DecodePredictionData(DecoderBuffer *buffer) override;
|
|
45
|
+
|
|
46
|
+
PredictionSchemeMethod GetPredictionMethod() const override {
|
|
47
|
+
return MESH_PREDICTION_TEX_COORDS_PORTABLE;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
bool IsInitialized() const override {
|
|
51
|
+
if (!predictor_.IsInitialized()) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
if (!this->mesh_data().IsInitialized()) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
int GetNumParentAttributes() const override { return 1; }
|
|
61
|
+
|
|
62
|
+
GeometryAttribute::Type GetParentAttributeType(int i) const override {
|
|
63
|
+
DRACO_DCHECK_EQ(i, 0);
|
|
64
|
+
(void)i;
|
|
65
|
+
return GeometryAttribute::POSITION;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
bool SetParentAttribute(const PointAttribute *att) override {
|
|
69
|
+
if (!att || att->attribute_type() != GeometryAttribute::POSITION) {
|
|
70
|
+
return false; // Invalid attribute type.
|
|
71
|
+
}
|
|
72
|
+
if (att->num_components() != 3) {
|
|
73
|
+
return false; // Currently works only for 3 component positions.
|
|
74
|
+
}
|
|
75
|
+
predictor_.SetPositionAttribute(*att);
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private:
|
|
80
|
+
MeshPredictionSchemeTexCoordsPortablePredictor<DataTypeT, MeshDataT>
|
|
81
|
+
predictor_;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
template <typename DataTypeT, class TransformT, class MeshDataT>
|
|
85
|
+
bool MeshPredictionSchemeTexCoordsPortableDecoder<
|
|
86
|
+
DataTypeT, TransformT,
|
|
87
|
+
MeshDataT>::ComputeOriginalValues(const CorrType *in_corr,
|
|
88
|
+
DataTypeT *out_data, int /* size */,
|
|
89
|
+
int num_components,
|
|
90
|
+
const PointIndex *entry_to_point_id_map) {
|
|
91
|
+
if (num_components != MeshPredictionSchemeTexCoordsPortablePredictor<
|
|
92
|
+
DataTypeT, MeshDataT>::kNumComponents) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
predictor_.SetEntryToPointIdMap(entry_to_point_id_map);
|
|
96
|
+
this->transform().Init(num_components);
|
|
97
|
+
|
|
98
|
+
const int corner_map_size =
|
|
99
|
+
static_cast<int>(this->mesh_data().data_to_corner_map()->size());
|
|
100
|
+
for (int p = 0; p < corner_map_size; ++p) {
|
|
101
|
+
const CornerIndex corner_id = this->mesh_data().data_to_corner_map()->at(p);
|
|
102
|
+
if (!predictor_.template ComputePredictedValue<false>(corner_id, out_data,
|
|
103
|
+
p)) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const int dst_offset = p * num_components;
|
|
108
|
+
this->transform().ComputeOriginalValue(predictor_.predicted_value(),
|
|
109
|
+
in_corr + dst_offset,
|
|
110
|
+
out_data + dst_offset);
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
template <typename DataTypeT, class TransformT, class MeshDataT>
|
|
116
|
+
bool MeshPredictionSchemeTexCoordsPortableDecoder<
|
|
117
|
+
DataTypeT, TransformT, MeshDataT>::DecodePredictionData(DecoderBuffer
|
|
118
|
+
*buffer) {
|
|
119
|
+
// Decode the delta coded orientations.
|
|
120
|
+
int32_t num_orientations = 0;
|
|
121
|
+
if (!buffer->Decode(&num_orientations) || num_orientations < 0) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
predictor_.ResizeOrientations(num_orientations);
|
|
125
|
+
bool last_orientation = true;
|
|
126
|
+
RAnsBitDecoder decoder;
|
|
127
|
+
if (!decoder.StartDecoding(buffer)) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
for (int i = 0; i < num_orientations; ++i) {
|
|
131
|
+
if (!decoder.DecodeNextBit()) {
|
|
132
|
+
last_orientation = !last_orientation;
|
|
133
|
+
}
|
|
134
|
+
predictor_.set_orientation(i, last_orientation);
|
|
135
|
+
}
|
|
136
|
+
decoder.EndDecoding();
|
|
137
|
+
return MeshPredictionSchemeDecoder<DataTypeT, TransformT,
|
|
138
|
+
MeshDataT>::DecodePredictionData(buffer);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
} // namespace draco
|
|
142
|
+
|
|
143
|
+
#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_PORTABLE_DECODER_H_
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// Copyright 2017 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_PORTABLE_ENCODER_H_
|
|
16
|
+
#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_PORTABLE_ENCODER_H_
|
|
17
|
+
|
|
18
|
+
#include "draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_encoder.h"
|
|
19
|
+
#include "draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_predictor.h"
|
|
20
|
+
#include "draco/compression/bit_coders/rans_bit_encoder.h"
|
|
21
|
+
|
|
22
|
+
namespace draco {
|
|
23
|
+
|
|
24
|
+
// Prediction scheme designed for predicting texture coordinates from known
|
|
25
|
+
// spatial position of vertices. For isometric parametrizations, the ratios
|
|
26
|
+
// between triangle edge lengths should be about the same in both the spatial
|
|
27
|
+
// and UV coordinate spaces, which makes the positions a good predictor for the
|
|
28
|
+
// UV coordinates. Note that this may not be the optimal approach for other
|
|
29
|
+
// parametrizations such as projective ones.
|
|
30
|
+
template <typename DataTypeT, class TransformT, class MeshDataT>
|
|
31
|
+
class MeshPredictionSchemeTexCoordsPortableEncoder
|
|
32
|
+
: public MeshPredictionSchemeEncoder<DataTypeT, TransformT, MeshDataT> {
|
|
33
|
+
public:
|
|
34
|
+
using CorrType = typename MeshPredictionSchemeEncoder<DataTypeT, TransformT,
|
|
35
|
+
MeshDataT>::CorrType;
|
|
36
|
+
MeshPredictionSchemeTexCoordsPortableEncoder(const PointAttribute *attribute,
|
|
37
|
+
const TransformT &transform,
|
|
38
|
+
const MeshDataT &mesh_data)
|
|
39
|
+
: MeshPredictionSchemeEncoder<DataTypeT, TransformT, MeshDataT>(
|
|
40
|
+
attribute, transform, mesh_data),
|
|
41
|
+
predictor_(mesh_data) {}
|
|
42
|
+
|
|
43
|
+
bool ComputeCorrectionValues(
|
|
44
|
+
const DataTypeT *in_data, CorrType *out_corr, int size,
|
|
45
|
+
int num_components, const PointIndex *entry_to_point_id_map) override;
|
|
46
|
+
|
|
47
|
+
bool EncodePredictionData(EncoderBuffer *buffer) override;
|
|
48
|
+
|
|
49
|
+
PredictionSchemeMethod GetPredictionMethod() const override {
|
|
50
|
+
return MESH_PREDICTION_TEX_COORDS_PORTABLE;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
bool IsInitialized() const override {
|
|
54
|
+
if (!predictor_.IsInitialized()) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
if (!this->mesh_data().IsInitialized()) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
int GetNumParentAttributes() const override { return 1; }
|
|
64
|
+
|
|
65
|
+
GeometryAttribute::Type GetParentAttributeType(int i) const override {
|
|
66
|
+
DRACO_DCHECK_EQ(i, 0);
|
|
67
|
+
(void)i;
|
|
68
|
+
return GeometryAttribute::POSITION;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
bool SetParentAttribute(const PointAttribute *att) override {
|
|
72
|
+
if (att->attribute_type() != GeometryAttribute::POSITION) {
|
|
73
|
+
return false; // Invalid attribute type.
|
|
74
|
+
}
|
|
75
|
+
if (att->num_components() != 3) {
|
|
76
|
+
return false; // Currently works only for 3 component positions.
|
|
77
|
+
}
|
|
78
|
+
predictor_.SetPositionAttribute(*att);
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private:
|
|
83
|
+
MeshPredictionSchemeTexCoordsPortablePredictor<DataTypeT, MeshDataT>
|
|
84
|
+
predictor_;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
template <typename DataTypeT, class TransformT, class MeshDataT>
|
|
88
|
+
bool MeshPredictionSchemeTexCoordsPortableEncoder<DataTypeT, TransformT,
|
|
89
|
+
MeshDataT>::
|
|
90
|
+
ComputeCorrectionValues(const DataTypeT *in_data, CorrType *out_corr,
|
|
91
|
+
int size, int num_components,
|
|
92
|
+
const PointIndex *entry_to_point_id_map) {
|
|
93
|
+
predictor_.SetEntryToPointIdMap(entry_to_point_id_map);
|
|
94
|
+
this->transform().Init(in_data, size, num_components);
|
|
95
|
+
// We start processing from the end because this prediction uses data from
|
|
96
|
+
// previous entries that could be overwritten when an entry is processed.
|
|
97
|
+
for (int p =
|
|
98
|
+
static_cast<int>(this->mesh_data().data_to_corner_map()->size() - 1);
|
|
99
|
+
p >= 0; --p) {
|
|
100
|
+
const CornerIndex corner_id = this->mesh_data().data_to_corner_map()->at(p);
|
|
101
|
+
if (!predictor_.template ComputePredictedValue<true>(corner_id, in_data,
|
|
102
|
+
p)) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const int dst_offset = p * num_components;
|
|
107
|
+
this->transform().ComputeCorrection(in_data + dst_offset,
|
|
108
|
+
predictor_.predicted_value(),
|
|
109
|
+
out_corr + dst_offset);
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
template <typename DataTypeT, class TransformT, class MeshDataT>
|
|
115
|
+
bool MeshPredictionSchemeTexCoordsPortableEncoder<
|
|
116
|
+
DataTypeT, TransformT, MeshDataT>::EncodePredictionData(EncoderBuffer
|
|
117
|
+
*buffer) {
|
|
118
|
+
// Encode the delta-coded orientations using arithmetic coding.
|
|
119
|
+
const int32_t num_orientations = predictor_.num_orientations();
|
|
120
|
+
buffer->Encode(num_orientations);
|
|
121
|
+
bool last_orientation = true;
|
|
122
|
+
RAnsBitEncoder encoder;
|
|
123
|
+
encoder.StartEncoding();
|
|
124
|
+
for (int i = 0; i < num_orientations; ++i) {
|
|
125
|
+
const bool orientation = predictor_.orientation(i);
|
|
126
|
+
encoder.EncodeBit(orientation == last_orientation);
|
|
127
|
+
last_orientation = orientation;
|
|
128
|
+
}
|
|
129
|
+
encoder.EndEncoding(buffer);
|
|
130
|
+
return MeshPredictionSchemeEncoder<DataTypeT, TransformT,
|
|
131
|
+
MeshDataT>::EncodePredictionData(buffer);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
} // namespace draco
|
|
135
|
+
|
|
136
|
+
#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_PORTABLE_ENCODER_H_
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// Copyright 2017 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_PORTABLE_PREDICTOR_H_
|
|
16
|
+
#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_PORTABLE_PREDICTOR_H_
|
|
17
|
+
|
|
18
|
+
#include <math.h>
|
|
19
|
+
|
|
20
|
+
#include <algorithm>
|
|
21
|
+
#include <limits>
|
|
22
|
+
|
|
23
|
+
#include "draco/attributes/point_attribute.h"
|
|
24
|
+
#include "draco/core/math_utils.h"
|
|
25
|
+
#include "draco/core/vector_d.h"
|
|
26
|
+
#include "draco/mesh/corner_table.h"
|
|
27
|
+
|
|
28
|
+
namespace draco {
|
|
29
|
+
|
|
30
|
+
// Predictor functionality used for portable UV prediction by both encoder and
|
|
31
|
+
// decoder.
|
|
32
|
+
template <typename DataTypeT, class MeshDataT>
|
|
33
|
+
class MeshPredictionSchemeTexCoordsPortablePredictor {
|
|
34
|
+
public:
|
|
35
|
+
static constexpr int kNumComponents = 2;
|
|
36
|
+
|
|
37
|
+
explicit MeshPredictionSchemeTexCoordsPortablePredictor(const MeshDataT &md)
|
|
38
|
+
: pos_attribute_(nullptr),
|
|
39
|
+
entry_to_point_id_map_(nullptr),
|
|
40
|
+
mesh_data_(md) {}
|
|
41
|
+
void SetPositionAttribute(const PointAttribute &position_attribute) {
|
|
42
|
+
pos_attribute_ = &position_attribute;
|
|
43
|
+
}
|
|
44
|
+
void SetEntryToPointIdMap(const PointIndex *map) {
|
|
45
|
+
entry_to_point_id_map_ = map;
|
|
46
|
+
}
|
|
47
|
+
bool IsInitialized() const { return pos_attribute_ != nullptr; }
|
|
48
|
+
|
|
49
|
+
VectorD<int64_t, 3> GetPositionForEntryId(int entry_id) const {
|
|
50
|
+
const PointIndex point_id = entry_to_point_id_map_[entry_id];
|
|
51
|
+
VectorD<int64_t, 3> pos;
|
|
52
|
+
pos_attribute_->ConvertValue(pos_attribute_->mapped_index(point_id),
|
|
53
|
+
&pos[0]);
|
|
54
|
+
return pos;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
VectorD<int64_t, 2> GetTexCoordForEntryId(int entry_id,
|
|
58
|
+
const DataTypeT *data) const {
|
|
59
|
+
const int data_offset = entry_id * kNumComponents;
|
|
60
|
+
return VectorD<int64_t, 2>(data[data_offset], data[data_offset + 1]);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Computes predicted UV coordinates on a given corner. The coordinates are
|
|
64
|
+
// stored in |predicted_value_| member.
|
|
65
|
+
template <bool is_encoder_t>
|
|
66
|
+
bool ComputePredictedValue(CornerIndex corner_id, const DataTypeT *data,
|
|
67
|
+
int data_id);
|
|
68
|
+
|
|
69
|
+
const DataTypeT *predicted_value() const { return predicted_value_; }
|
|
70
|
+
bool orientation(int i) const { return orientations_[i]; }
|
|
71
|
+
void set_orientation(int i, bool v) { orientations_[i] = v; }
|
|
72
|
+
size_t num_orientations() const { return orientations_.size(); }
|
|
73
|
+
void ResizeOrientations(int num_orientations) {
|
|
74
|
+
orientations_.resize(num_orientations);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private:
|
|
78
|
+
const PointAttribute *pos_attribute_;
|
|
79
|
+
const PointIndex *entry_to_point_id_map_;
|
|
80
|
+
DataTypeT predicted_value_[kNumComponents];
|
|
81
|
+
// Encoded / decoded array of UV flips.
|
|
82
|
+
// TODO(ostava): We should remove this and replace this with in-place encoding
|
|
83
|
+
// and decoding to avoid unnecessary copy.
|
|
84
|
+
std::vector<bool> orientations_;
|
|
85
|
+
MeshDataT mesh_data_;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
template <typename DataTypeT, class MeshDataT>
|
|
89
|
+
template <bool is_encoder_t>
|
|
90
|
+
bool MeshPredictionSchemeTexCoordsPortablePredictor<
|
|
91
|
+
DataTypeT, MeshDataT>::ComputePredictedValue(CornerIndex corner_id,
|
|
92
|
+
const DataTypeT *data,
|
|
93
|
+
int data_id) {
|
|
94
|
+
// Compute the predicted UV coordinate from the positions on all corners
|
|
95
|
+
// of the processed triangle. For the best prediction, the UV coordinates
|
|
96
|
+
// on the next/previous corners need to be already encoded/decoded.
|
|
97
|
+
const CornerIndex next_corner_id = mesh_data_.corner_table()->Next(corner_id);
|
|
98
|
+
const CornerIndex prev_corner_id =
|
|
99
|
+
mesh_data_.corner_table()->Previous(corner_id);
|
|
100
|
+
// Get the encoded data ids from the next and previous corners.
|
|
101
|
+
// The data id is the encoding order of the UV coordinates.
|
|
102
|
+
int next_data_id, prev_data_id;
|
|
103
|
+
|
|
104
|
+
int next_vert_id, prev_vert_id;
|
|
105
|
+
next_vert_id = mesh_data_.corner_table()->Vertex(next_corner_id).value();
|
|
106
|
+
prev_vert_id = mesh_data_.corner_table()->Vertex(prev_corner_id).value();
|
|
107
|
+
|
|
108
|
+
next_data_id = mesh_data_.vertex_to_data_map()->at(next_vert_id);
|
|
109
|
+
prev_data_id = mesh_data_.vertex_to_data_map()->at(prev_vert_id);
|
|
110
|
+
|
|
111
|
+
typedef VectorD<int64_t, 2> Vec2;
|
|
112
|
+
typedef VectorD<int64_t, 3> Vec3;
|
|
113
|
+
typedef VectorD<uint64_t, 2> Vec2u;
|
|
114
|
+
|
|
115
|
+
if (prev_data_id < data_id && next_data_id < data_id) {
|
|
116
|
+
// Both other corners have available UV coordinates for prediction.
|
|
117
|
+
const Vec2 n_uv = GetTexCoordForEntryId(next_data_id, data);
|
|
118
|
+
const Vec2 p_uv = GetTexCoordForEntryId(prev_data_id, data);
|
|
119
|
+
if (p_uv == n_uv) {
|
|
120
|
+
// We cannot do a reliable prediction on degenerated UV triangles.
|
|
121
|
+
predicted_value_[0] = p_uv[0];
|
|
122
|
+
predicted_value_[1] = p_uv[1];
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Get positions at all corners.
|
|
127
|
+
const Vec3 tip_pos = GetPositionForEntryId(data_id);
|
|
128
|
+
const Vec3 next_pos = GetPositionForEntryId(next_data_id);
|
|
129
|
+
const Vec3 prev_pos = GetPositionForEntryId(prev_data_id);
|
|
130
|
+
// We use the positions of the above triangle to predict the texture
|
|
131
|
+
// coordinate on the tip corner C.
|
|
132
|
+
// To convert the triangle into the UV coordinate system we first compute
|
|
133
|
+
// position X on the vector |prev_pos - next_pos| that is the projection of
|
|
134
|
+
// point C onto vector |prev_pos - next_pos|:
|
|
135
|
+
//
|
|
136
|
+
// C
|
|
137
|
+
// /. \
|
|
138
|
+
// / . \
|
|
139
|
+
// / . \
|
|
140
|
+
// N---X----------P
|
|
141
|
+
//
|
|
142
|
+
// Where next_pos is point (N), prev_pos is point (P) and tip_pos is the
|
|
143
|
+
// position of predicted coordinate (C).
|
|
144
|
+
//
|
|
145
|
+
const Vec3 pn = prev_pos - next_pos;
|
|
146
|
+
const uint64_t pn_norm2_squared = pn.SquaredNorm();
|
|
147
|
+
if (pn_norm2_squared != 0) {
|
|
148
|
+
// Compute the projection of C onto PN by computing dot product of CN with
|
|
149
|
+
// PN and normalizing it by length of PN. This gives us a factor |s| where
|
|
150
|
+
// |s = PN.Dot(CN) / PN.SquaredNorm2()|. This factor can be used to
|
|
151
|
+
// compute X in UV space |X_UV| as |X_UV = N_UV + s * PN_UV|.
|
|
152
|
+
const Vec3 cn = tip_pos - next_pos;
|
|
153
|
+
const int64_t cn_dot_pn = pn.Dot(cn);
|
|
154
|
+
|
|
155
|
+
const Vec2 pn_uv = p_uv - n_uv;
|
|
156
|
+
// Because we perform all computations with integers, we don't explicitly
|
|
157
|
+
// compute the normalized factor |s|, but rather we perform all operations
|
|
158
|
+
// over UV vectors in a non-normalized coordinate system scaled with a
|
|
159
|
+
// scaling factor |pn_norm2_squared|:
|
|
160
|
+
//
|
|
161
|
+
// x_uv = X_UV * PN.Norm2Squared()
|
|
162
|
+
//
|
|
163
|
+
const int64_t n_uv_absmax_element =
|
|
164
|
+
std::max(std::abs(n_uv[0]), std::abs(n_uv[1]));
|
|
165
|
+
if (n_uv_absmax_element >
|
|
166
|
+
std::numeric_limits<int64_t>::max() / pn_norm2_squared) {
|
|
167
|
+
// Return false if the below multiplication would overflow.
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
const int64_t pn_uv_absmax_element =
|
|
171
|
+
std::max(std::abs(pn_uv[0]), std::abs(pn_uv[1]));
|
|
172
|
+
if (std::abs(cn_dot_pn) >
|
|
173
|
+
std::numeric_limits<int64_t>::max() / pn_uv_absmax_element) {
|
|
174
|
+
// Return false if squared length calculation would overflow.
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
const Vec2 x_uv = n_uv * pn_norm2_squared + (cn_dot_pn * pn_uv);
|
|
178
|
+
const int64_t pn_absmax_element =
|
|
179
|
+
std::max(std::max(std::abs(pn[0]), std::abs(pn[1])), std::abs(pn[2]));
|
|
180
|
+
if (std::abs(cn_dot_pn) >
|
|
181
|
+
std::numeric_limits<int64_t>::max() / pn_absmax_element) {
|
|
182
|
+
// Return false if squared length calculation would overflow.
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Compute squared length of vector CX in position coordinate system:
|
|
187
|
+
const Vec3 x_pos = next_pos + (cn_dot_pn * pn) / pn_norm2_squared;
|
|
188
|
+
const uint64_t cx_norm2_squared = (tip_pos - x_pos).SquaredNorm();
|
|
189
|
+
|
|
190
|
+
// Compute vector CX_UV in the uv space by rotating vector PN_UV by 90
|
|
191
|
+
// degrees and scaling it with factor CX.Norm2() / PN.Norm2():
|
|
192
|
+
//
|
|
193
|
+
// CX_UV = (CX.Norm2() / PN.Norm2()) * Rot(PN_UV)
|
|
194
|
+
//
|
|
195
|
+
// To preserve precision, we perform all operations in scaled space as
|
|
196
|
+
// explained above, so we want the final vector to be:
|
|
197
|
+
//
|
|
198
|
+
// cx_uv = CX_UV * PN.Norm2Squared()
|
|
199
|
+
//
|
|
200
|
+
// We can then rewrite the formula as:
|
|
201
|
+
//
|
|
202
|
+
// cx_uv = CX.Norm2() * PN.Norm2() * Rot(PN_UV)
|
|
203
|
+
//
|
|
204
|
+
Vec2 cx_uv(pn_uv[1], -pn_uv[0]); // Rotated PN_UV.
|
|
205
|
+
// Compute CX.Norm2() * PN.Norm2()
|
|
206
|
+
const uint64_t norm_squared =
|
|
207
|
+
IntSqrt(cx_norm2_squared * pn_norm2_squared);
|
|
208
|
+
// Final cx_uv in the scaled coordinate space.
|
|
209
|
+
cx_uv = cx_uv * norm_squared;
|
|
210
|
+
|
|
211
|
+
// Predicted uv coordinate is then computed by either adding or
|
|
212
|
+
// subtracting CX_UV to/from X_UV.
|
|
213
|
+
Vec2 predicted_uv;
|
|
214
|
+
if (is_encoder_t) {
|
|
215
|
+
// When encoding, compute both possible vectors and determine which one
|
|
216
|
+
// results in a better prediction.
|
|
217
|
+
// Both vectors need to be transformed back from the scaled space to
|
|
218
|
+
// the real UV coordinate space.
|
|
219
|
+
const Vec2 predicted_uv_0((x_uv + cx_uv) / pn_norm2_squared);
|
|
220
|
+
const Vec2 predicted_uv_1((x_uv - cx_uv) / pn_norm2_squared);
|
|
221
|
+
const Vec2 c_uv = GetTexCoordForEntryId(data_id, data);
|
|
222
|
+
if ((c_uv - predicted_uv_0).SquaredNorm() <
|
|
223
|
+
(c_uv - predicted_uv_1).SquaredNorm()) {
|
|
224
|
+
predicted_uv = predicted_uv_0;
|
|
225
|
+
orientations_.push_back(true);
|
|
226
|
+
} else {
|
|
227
|
+
predicted_uv = predicted_uv_1;
|
|
228
|
+
orientations_.push_back(false);
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
// When decoding the data, we already know which orientation to use.
|
|
232
|
+
if (orientations_.empty()) {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
const bool orientation = orientations_.back();
|
|
236
|
+
orientations_.pop_back();
|
|
237
|
+
// Perform operations in unsigned type to avoid signed integer overflow.
|
|
238
|
+
// Note that the result will be the same (for non-overflowing values).
|
|
239
|
+
if (orientation) {
|
|
240
|
+
predicted_uv = Vec2(Vec2u(x_uv) + Vec2u(cx_uv)) / pn_norm2_squared;
|
|
241
|
+
} else {
|
|
242
|
+
predicted_uv = Vec2(Vec2u(x_uv) - Vec2u(cx_uv)) / pn_norm2_squared;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
predicted_value_[0] = static_cast<int>(predicted_uv[0]);
|
|
246
|
+
predicted_value_[1] = static_cast<int>(predicted_uv[1]);
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
// Else we don't have available textures on both corners or the position data
|
|
251
|
+
// is invalid. For such cases we can't use positions for predicting the uv
|
|
252
|
+
// value and we resort to delta coding.
|
|
253
|
+
int data_offset = 0;
|
|
254
|
+
if (prev_data_id < data_id) {
|
|
255
|
+
// Use the value on the previous corner as the prediction.
|
|
256
|
+
data_offset = prev_data_id * kNumComponents;
|
|
257
|
+
}
|
|
258
|
+
if (next_data_id < data_id) {
|
|
259
|
+
// Use the value on the next corner as the prediction.
|
|
260
|
+
data_offset = next_data_id * kNumComponents;
|
|
261
|
+
} else {
|
|
262
|
+
// None of the other corners have a valid value. Use the last encoded value
|
|
263
|
+
// as the prediction if possible.
|
|
264
|
+
if (data_id > 0) {
|
|
265
|
+
data_offset = (data_id - 1) * kNumComponents;
|
|
266
|
+
} else {
|
|
267
|
+
// We are encoding the first value. Predict 0.
|
|
268
|
+
for (int i = 0; i < kNumComponents; ++i) {
|
|
269
|
+
predicted_value_[i] = 0;
|
|
270
|
+
}
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
for (int i = 0; i < kNumComponents; ++i) {
|
|
275
|
+
predicted_value_[i] = data[data_offset + i];
|
|
276
|
+
}
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
} // namespace draco
|
|
281
|
+
|
|
282
|
+
#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_PORTABLE_PREDICTOR_H_
|
|
@@ -0,0 +1,90 @@
|
|
|
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_PREDICTION_SCHEME_DECODER_H_
|
|
16
|
+
#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_DECODER_H_
|
|
17
|
+
|
|
18
|
+
#include <type_traits>
|
|
19
|
+
|
|
20
|
+
#include "draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_interface.h"
|
|
21
|
+
#include "draco/compression/attributes/prediction_schemes/prediction_scheme_decoding_transform.h"
|
|
22
|
+
|
|
23
|
+
// Prediction schemes can be used during encoding and decoding of vertex
|
|
24
|
+
// attributes to predict attribute values based on the previously
|
|
25
|
+
// encoded/decoded data. The differences between the original and predicted
|
|
26
|
+
// attribute values are used to compute correction values that can be usually
|
|
27
|
+
// encoded with fewer bits compared to the original data.
|
|
28
|
+
namespace draco {
|
|
29
|
+
|
|
30
|
+
// Abstract base class for typed prediction schemes. It provides basic access
|
|
31
|
+
// to the encoded attribute and to the supplied prediction transform.
|
|
32
|
+
template <typename DataTypeT,
|
|
33
|
+
class TransformT =
|
|
34
|
+
PredictionSchemeDecodingTransform<DataTypeT, DataTypeT>>
|
|
35
|
+
class PredictionSchemeDecoder : public PredictionSchemeTypedDecoderInterface<
|
|
36
|
+
DataTypeT, typename TransformT::CorrType> {
|
|
37
|
+
public:
|
|
38
|
+
typedef DataTypeT DataType;
|
|
39
|
+
typedef TransformT Transform;
|
|
40
|
+
// Correction type needs to be defined in the prediction transform class.
|
|
41
|
+
typedef typename Transform::CorrType CorrType;
|
|
42
|
+
explicit PredictionSchemeDecoder(const PointAttribute *attribute)
|
|
43
|
+
: PredictionSchemeDecoder(attribute, Transform()) {}
|
|
44
|
+
PredictionSchemeDecoder(const PointAttribute *attribute,
|
|
45
|
+
const Transform &transform)
|
|
46
|
+
: attribute_(attribute), transform_(transform) {}
|
|
47
|
+
|
|
48
|
+
bool DecodePredictionData(DecoderBuffer *buffer) override {
|
|
49
|
+
if (!transform_.DecodeTransformData(buffer)) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const PointAttribute *GetAttribute() const override { return attribute(); }
|
|
56
|
+
|
|
57
|
+
// Returns the number of parent attributes that are needed for the prediction.
|
|
58
|
+
int GetNumParentAttributes() const override { return 0; }
|
|
59
|
+
|
|
60
|
+
// Returns the type of each of the parent attribute.
|
|
61
|
+
GeometryAttribute::Type GetParentAttributeType(int /* i */) const override {
|
|
62
|
+
return GeometryAttribute::INVALID;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Sets the required parent attribute.
|
|
66
|
+
bool SetParentAttribute(const PointAttribute * /* att */) override {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
bool AreCorrectionsPositive() override {
|
|
71
|
+
return transform_.AreCorrectionsPositive();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
PredictionSchemeTransformType GetTransformType() const override {
|
|
75
|
+
return transform_.GetType();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
protected:
|
|
79
|
+
inline const PointAttribute *attribute() const { return attribute_; }
|
|
80
|
+
inline const Transform &transform() const { return transform_; }
|
|
81
|
+
inline Transform &transform() { return transform_; }
|
|
82
|
+
|
|
83
|
+
private:
|
|
84
|
+
const PointAttribute *attribute_;
|
|
85
|
+
Transform transform_;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
} // namespace draco
|
|
89
|
+
|
|
90
|
+
#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_DECODER_H_
|