GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
mesh_prediction_scheme_multi_parallelogram_decoder.h
Go to the documentation of this file.
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_MULTI_PARALLELOGRAM_DECODER_H_
17#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_MULTI_PARALLELOGRAM_DECODER_H_
18
23
24namespace draco {
25
26// Decoder for predictions encoded by multi-parallelogram encoding scheme.
27// See the corresponding encoder for method description.
28template <typename DataTypeT, class TransformT, class MeshDataT>
29class MeshPredictionSchemeMultiParallelogramDecoder
30 : public MeshPredictionSchemeDecoder<DataTypeT, TransformT, MeshDataT> {
31 public:
32 using CorrType =
33 typename PredictionSchemeDecoder<DataTypeT, TransformT>::CorrType;
34 using CornerTable = typename MeshDataT::CornerTable;
35
36 explicit MeshPredictionSchemeMultiParallelogramDecoder(
37 const PointAttribute *attribute)
38 : MeshPredictionSchemeDecoder<DataTypeT, TransformT, MeshDataT>(
39 attribute) {}
40 MeshPredictionSchemeMultiParallelogramDecoder(const PointAttribute *attribute,
41 const TransformT &transform,
42 const MeshDataT &mesh_data)
43 : MeshPredictionSchemeDecoder<DataTypeT, TransformT, MeshDataT>(
44 attribute, transform, mesh_data) {}
45
46 bool ComputeOriginalValues(const CorrType *in_corr, DataTypeT *out_data,
47 int size, int num_components,
48 const PointIndex *entry_to_point_id_map) override;
49 PredictionSchemeMethod GetPredictionMethod() const override {
51 }
52
53 bool IsInitialized() const override {
54 return this->mesh_data().IsInitialized();
55 }
56};
57
58template <typename DataTypeT, class TransformT, class MeshDataT>
59bool MeshPredictionSchemeMultiParallelogramDecoder<DataTypeT, TransformT,
60 MeshDataT>::
61 ComputeOriginalValues(const CorrType *in_corr, DataTypeT *out_data,
62 int /* size */, int num_components,
63 const PointIndex * /* entry_to_point_id_map */) {
64 this->transform().Init(num_components);
65
66 // For storage of prediction values (already initialized to zero).
67 std::unique_ptr<DataTypeT[]> pred_vals(new DataTypeT[num_components]());
68 std::unique_ptr<DataTypeT[]> parallelogram_pred_vals(
69 new DataTypeT[num_components]());
70
71 this->transform().ComputeOriginalValue(pred_vals.get(), in_corr, out_data);
72
73 const CornerTable *const table = this->mesh_data().corner_table();
74 const std::vector<int32_t> *const vertex_to_data_map =
75 this->mesh_data().vertex_to_data_map();
76
77 const int corner_map_size =
78 static_cast<int>(this->mesh_data().data_to_corner_map()->size());
79 for (int p = 1; p < corner_map_size; ++p) {
80 const CornerIndex start_corner_id =
81 this->mesh_data().data_to_corner_map()->at(p);
82
83 CornerIndex corner_id(start_corner_id);
84 int num_parallelograms = 0;
85 for (int i = 0; i < num_components; ++i) {
86 pred_vals[i] = static_cast<DataTypeT>(0);
87 }
88 while (corner_id != kInvalidCornerIndex) {
90 p, corner_id, table, *vertex_to_data_map, out_data,
91 num_components, parallelogram_pred_vals.get())) {
92 for (int c = 0; c < num_components; ++c) {
93 pred_vals[c] =
94 AddAsUnsigned(pred_vals[c], parallelogram_pred_vals[c]);
95 }
96 ++num_parallelograms;
97 }
98
99 // Proceed to the next corner attached to the vertex.
100 corner_id = table->SwingRight(corner_id);
101 if (corner_id == start_corner_id) {
102 corner_id = kInvalidCornerIndex;
103 }
104 }
105
106 const int dst_offset = p * num_components;
107 if (num_parallelograms == 0) {
108 // No parallelogram was valid.
109 // We use the last decoded point as a reference.
110 const int src_offset = (p - 1) * num_components;
111 this->transform().ComputeOriginalValue(
112 out_data + src_offset, in_corr + dst_offset, out_data + dst_offset);
113 } else {
114 // Compute the correction from the predicted value.
115 for (int c = 0; c < num_components; ++c) {
116 pred_vals[c] /= num_parallelograms;
117 }
118 this->transform().ComputeOriginalValue(
119 pred_vals.get(), in_corr + dst_offset, out_data + dst_offset);
120 }
121 }
122 return true;
123}
124
125} // namespace draco
126
127#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_MULTI_PARALLELOGRAM_DECODER_H_
128#endif
Definition corner_table.h:53
Definition mesh_prediction_scheme_decoder.h:28
n< br > font size
Definition meshpage.php:3536
Definition attribute_octahedron_transform.cc:21
bool ComputeParallelogramPrediction(int data_entry_id, const CornerIndex ci, const CornerTableT *table, const std::vector< int32_t > &vertex_to_data_map, const DataTypeT *in_data, int num_components, DataTypeT *out_prediction)
Definition mesh_prediction_scheme_parallelogram_shared.h:45
CornerIndex CornerIndex
Definition mesh_edgebreaker_encoder_impl.cc:35
PredictionSchemeMethod
Definition compression_shared.h:80
@ MESH_PREDICTION_MULTI_PARALLELOGRAM
Definition compression_shared.h:87
DataTypeT AddAsUnsigned(DataTypeT a, DataTypeT b)
Definition math_utils.h:63