GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
mesh_prediction_scheme_tex_coords_portable_decoder.h
Go to the documentation of this file.
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
21
22namespace 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.
27template <typename DataTypeT, class TransformT, class MeshDataT>
29 : public MeshPredictionSchemeDecoder<DataTypeT, TransformT, MeshDataT> {
30 public:
31 using CorrType = typename MeshPredictionSchemeDecoder<DataTypeT, TransformT,
32 MeshDataT>::CorrType;
34 const TransformT &transform,
35 const MeshDataT &mesh_data)
36 : MeshPredictionSchemeDecoder<DataTypeT, TransformT, MeshDataT>(
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
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
63 DRACO_DCHECK_EQ(i, 0);
64 (void)i;
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:
81 predictor_;
82};
83
84template <typename DataTypeT, class TransformT, class MeshDataT>
85bool 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) {
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
115template <typename DataTypeT, class TransformT, class MeshDataT>
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_
Definition decoder_buffer.h:30
bool Decode(T *out_val)
Definition decoder_buffer.h:68
uint8_t num_components() const
Definition geometry_attribute.h:263
Type attribute_type() const
Definition geometry_attribute.h:256
Type
Definition geometry_attribute.h:46
@ POSITION
Definition geometry_attribute.h:52
const MeshData & mesh_data() const
Definition mesh_prediction_scheme_decoder.h:38
MeshPredictionSchemeDecoder(const PointAttribute *attribute, const TransformT &transform, const MeshDataT &mesh_data)
Definition mesh_prediction_scheme_decoder.h:31
Definition mesh_prediction_scheme_tex_coords_portable_decoder.h:29
int GetNumParentAttributes() const override
Definition mesh_prediction_scheme_tex_coords_portable_decoder.h:60
MeshPredictionSchemeTexCoordsPortableDecoder(const PointAttribute *attribute, const TransformT &transform, const MeshDataT &mesh_data)
Definition mesh_prediction_scheme_tex_coords_portable_decoder.h:33
bool SetParentAttribute(const PointAttribute *att) override
Definition mesh_prediction_scheme_tex_coords_portable_decoder.h:68
bool DecodePredictionData(DecoderBuffer *buffer) override
Definition mesh_prediction_scheme_tex_coords_portable_decoder.h:117
bool IsInitialized() const override
Definition mesh_prediction_scheme_tex_coords_portable_decoder.h:50
typename MeshPredictionSchemeDecoder< DataTypeT, TransformT, MeshDataT >::CorrType CorrType
Definition mesh_prediction_scheme_tex_coords_portable_decoder.h:31
PredictionSchemeMethod GetPredictionMethod() const override
Definition mesh_prediction_scheme_tex_coords_portable_decoder.h:46
bool ComputeOriginalValues(const CorrType *in_corr, DataTypeT *out_data, int size, int num_components, const PointIndex *entry_to_point_id_map) override
Definition mesh_prediction_scheme_tex_coords_portable_decoder.h:87
GeometryAttribute::Type GetParentAttributeType(int i) const override
Definition mesh_prediction_scheme_tex_coords_portable_decoder.h:62
Definition mesh_prediction_scheme_tex_coords_portable_predictor.h:33
Definition point_attribute.h:33
const Transform & transform() const
Definition prediction_scheme_decoder.h:80
const PointAttribute * attribute() const
Definition prediction_scheme_decoder.h:79
Definition rans_bit_decoder.h:28
bool StartDecoding(DecoderBuffer *source_buffer)
Definition rans_bit_decoder.cc:29
void EndDecoding()
Definition rans_bit_decoder.h:44
bool DecodeNextBit()
Definition rans_bit_decoder.cc:65
#define DRACO_DCHECK_EQ(a, b)
Definition macros.h:81
n< br > font size
Definition meshpage.php:3536
Definition attribute_octahedron_transform.cc:21
CornerIndex CornerIndex
Definition mesh_edgebreaker_encoder_impl.cc:35
PredictionSchemeMethod
Definition compression_shared.h:80
@ MESH_PREDICTION_TEX_COORDS_PORTABLE
Definition compression_shared.h:90
Definition GameApi_pl.cc:29382