GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
mesh_prediction_scheme_geometric_normal_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_GEOMETRIC_NORMAL_DECODER_H_
16#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_GEOMETRIC_NORMAL_DECODER_H_
17
22
23namespace draco {
24
25// See MeshPredictionSchemeGeometricNormalEncoder for documentation.
26template <typename DataTypeT, class TransformT, class MeshDataT>
28 : public MeshPredictionSchemeDecoder<DataTypeT, TransformT, MeshDataT> {
29 public:
30 using CorrType = typename MeshPredictionSchemeDecoder<DataTypeT, TransformT,
31 MeshDataT>::CorrType;
33 const TransformT &transform,
34 const MeshDataT &mesh_data)
35 : MeshPredictionSchemeDecoder<DataTypeT, TransformT, MeshDataT>(
37 predictor_(mesh_data) {}
38
39 private:
41
42 public:
43 bool ComputeOriginalValues(const CorrType *in_corr, DataTypeT *out_data,
44 int size, int num_components,
45 const PointIndex *entry_to_point_id_map) override;
46
47 bool DecodePredictionData(DecoderBuffer *buffer) override;
48
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 if (!octahedron_tool_box_.IsInitialized()) {
61 return false;
62 }
63 return true;
64 }
65
66 int GetNumParentAttributes() const override { return 1; }
67
69 DRACO_DCHECK_EQ(i, 0);
70 (void)i;
72 }
73
74 bool SetParentAttribute(const PointAttribute *att) override {
76 return false; // Invalid attribute type.
77 }
78 if (att->num_components() != 3) {
79 return false; // Currently works only for 3 component positions.
80 }
81 predictor_.SetPositionAttribute(*att);
82 return true;
83 }
84 void SetQuantizationBits(int q) {
85 octahedron_tool_box_.SetQuantizationBits(q);
86 }
87
88 private:
90 MeshDataT>
91 predictor_;
92 OctahedronToolBox octahedron_tool_box_;
93 RAnsBitDecoder flip_normal_bit_decoder_;
94};
95
96template <typename DataTypeT, class TransformT, class MeshDataT>
97bool MeshPredictionSchemeGeometricNormalDecoder<
98 DataTypeT, TransformT,
99 MeshDataT>::ComputeOriginalValues(const CorrType *in_corr,
100 DataTypeT *out_data, int /* size */,
101 int num_components,
102 const PointIndex *entry_to_point_id_map) {
103 this->SetQuantizationBits(this->transform().quantization_bits());
104 predictor_.SetEntryToPointIdMap(entry_to_point_id_map);
106
107 // Expecting in_data in octahedral coordinates, i.e., portable attribute.
108 DRACO_DCHECK_EQ(num_components, 2);
109
110 const int corner_map_size =
111 static_cast<int>(this->mesh_data().data_to_corner_map()->size());
112
113 VectorD<int32_t, 3> pred_normal_3d;
114 int32_t pred_normal_oct[2];
115
116 for (int data_id = 0; data_id < corner_map_size; ++data_id) {
117 const CornerIndex corner_id =
118 this->mesh_data().data_to_corner_map()->at(data_id);
119 predictor_.ComputePredictedValue(corner_id, pred_normal_3d.data());
120
121 // Compute predicted octahedral coordinates.
122 octahedron_tool_box_.CanonicalizeIntegerVector(pred_normal_3d.data());
123 DRACO_DCHECK_EQ(pred_normal_3d.AbsSum(),
124 octahedron_tool_box_.center_value());
125 if (flip_normal_bit_decoder_.DecodeNextBit()) {
126 pred_normal_3d = -pred_normal_3d;
127 }
128 octahedron_tool_box_.IntegerVectorToQuantizedOctahedralCoords(
129 pred_normal_3d.data(), pred_normal_oct, pred_normal_oct + 1);
130
131 const int data_offset = data_id * 2;
132 this->transform().ComputeOriginalValue(
133 pred_normal_oct, in_corr + data_offset, out_data + data_offset);
134 }
135 flip_normal_bit_decoder_.EndDecoding();
136 return true;
137}
138
139template <typename DataTypeT, class TransformT, class MeshDataT>
141 DataTypeT, TransformT, MeshDataT>::DecodePredictionData(DecoderBuffer
142 *buffer) {
143 // Get data needed for transform
144 if (!this->transform().DecodeTransformData(buffer)) {
145 return false;
146 }
147
148#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
149 if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 2)) {
150 uint8_t prediction_mode;
151 if (!buffer->Decode(&prediction_mode)) {
152 return false;
153 }
154
155 if (!predictor_.SetNormalPredictionMode(
156 NormalPredictionMode(prediction_mode))) {
157 return false;
158 }
159 }
160#endif
161
162 // Init normal flips.
163 if (!flip_normal_bit_decoder_.StartDecoding(buffer)) {
164 return false;
165 }
166
167 return true;
168}
169
170} // namespace draco
171
172#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_GEOMETRIC_NORMAL_DECODER_H_
Definition decoder_buffer.h:30
uint16_t bitstream_version() const
Definition decoder_buffer.h:120
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_geometric_normal_decoder.h:28
PredictionSchemeMethod GetPredictionMethod() const override
Definition mesh_prediction_scheme_geometric_normal_decoder.h:49
int GetNumParentAttributes() const override
Definition mesh_prediction_scheme_geometric_normal_decoder.h:66
void SetQuantizationBits(int q)
Definition mesh_prediction_scheme_geometric_normal_decoder.h:84
GeometryAttribute::Type GetParentAttributeType(int i) const override
Definition mesh_prediction_scheme_geometric_normal_decoder.h:68
bool DecodePredictionData(DecoderBuffer *buffer) override
Definition mesh_prediction_scheme_geometric_normal_decoder.h:141
bool IsInitialized() const override
Definition mesh_prediction_scheme_geometric_normal_decoder.h:53
MeshPredictionSchemeGeometricNormalDecoder(const PointAttribute *attribute, const TransformT &transform, const MeshDataT &mesh_data)
Definition mesh_prediction_scheme_geometric_normal_decoder.h:32
typename MeshPredictionSchemeDecoder< DataTypeT, TransformT, MeshDataT >::CorrType CorrType
Definition mesh_prediction_scheme_geometric_normal_decoder.h:30
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_geometric_normal_decoder.h:99
bool SetParentAttribute(const PointAttribute *att) override
Definition mesh_prediction_scheme_geometric_normal_decoder.h:74
Definition mesh_prediction_scheme_geometric_normal_predictor_area.h:27
Definition normal_compression_utils.h:50
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
Definition vector_d.h:30
Scalar AbsSum() const
Definition vector_d.h:237
Scalar * data()
Definition vector_d.h:282
#define DRACO_DCHECK_EQ(a, b)
Definition macros.h:81
#define DRACO_DCHECK(x)
Definition macros.h:80
#define DRACO_BITSTREAM_VERSION(MAJOR, MINOR)
Definition macros.h:114
n< br > font size
Definition meshpage.php:3536
Definition attribute_octahedron_transform.cc:21
NormalPredictionMode
Definition compression_shared.h:138
CornerIndex CornerIndex
Definition mesh_edgebreaker_encoder_impl.cc:35
PredictionSchemeMethod
Definition compression_shared.h:80
@ MESH_PREDICTION_GEOMETRIC_NORMAL
Definition compression_shared.h:91
Definition GameApi_pl.cc:29382