GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
mesh_prediction_scheme_multi_parallelogram_encoder.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#ifndef DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_MULTI_PARALLELOGRAM_ENCODER_H_
16#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_MULTI_PARALLELOGRAM_ENCODER_H_
17
20
21namespace draco {
22
23// Multi parallelogram prediction predicts attribute values using information
24// from all opposite faces to the predicted vertex, compared to the standard
25// prediction scheme, where only one opposite face is used (see
26// prediction_scheme_parallelogram.h). This approach is generally slower than
27// the standard parallelogram prediction, but it usually results in better
28// prediction (5 - 20% based on the quantization level. Better gains can be
29// achieved when more aggressive quantization is used).
30template <typename DataTypeT, class TransformT, class MeshDataT>
32 : public MeshPredictionSchemeEncoder<DataTypeT, TransformT, MeshDataT> {
33 public:
34 using CorrType =
36 using CornerTable = typename MeshDataT::CornerTable;
37
40 : MeshPredictionSchemeEncoder<DataTypeT, TransformT, MeshDataT>(
41 attribute) {}
43 const TransformT &transform,
44 const MeshDataT &mesh_data)
45 : MeshPredictionSchemeEncoder<DataTypeT, TransformT, MeshDataT>(
47
49 const DataTypeT *in_data, CorrType *out_corr, int size,
50 int num_components, const PointIndex *entry_to_point_id_map) override;
54
55 bool IsInitialized() const override {
56 return this->mesh_data().IsInitialized();
57 }
58};
59
60template <typename DataTypeT, class TransformT, class MeshDataT>
61bool MeshPredictionSchemeMultiParallelogramEncoder<DataTypeT, TransformT,
62 MeshDataT>::
63 ComputeCorrectionValues(const DataTypeT *in_data, CorrType *out_corr,
64 int size, int num_components,
65 const PointIndex * /* entry_to_point_id_map */) {
66 this->transform().Init(in_data, size, num_components);
67 const CornerTable *const table = this->mesh_data().corner_table();
68 const std::vector<int32_t> *const vertex_to_data_map =
69 this->mesh_data().vertex_to_data_map();
70
71 // For storage of prediction values (already initialized to zero).
72 std::unique_ptr<DataTypeT[]> pred_vals(new DataTypeT[num_components]());
73 std::unique_ptr<DataTypeT[]> parallelogram_pred_vals(
74 new DataTypeT[num_components]());
75
76 // We start processing from the end because this prediction uses data from
77 // previous entries that could be overwritten when an entry is processed.
78 for (int p =
79 static_cast<int>(this->mesh_data().data_to_corner_map()->size() - 1);
80 p > 0; --p) {
81 const CornerIndex start_corner_id =
82 this->mesh_data().data_to_corner_map()->at(p);
83
84 // Go over all corners attached to the vertex and compute the predicted
85 // value from the parallelograms defined by their opposite faces.
86 CornerIndex corner_id(start_corner_id);
87 int num_parallelograms = 0;
88 for (int i = 0; i < num_components; ++i) {
89 pred_vals[i] = static_cast<DataTypeT>(0);
90 }
91 while (corner_id != kInvalidCornerIndex) {
93 p, corner_id, table, *vertex_to_data_map, in_data, num_components,
94 parallelogram_pred_vals.get())) {
95 for (int c = 0; c < num_components; ++c) {
96 pred_vals[c] += parallelogram_pred_vals[c];
97 }
98 ++num_parallelograms;
99 }
100
101 // Proceed to the next corner attached to the vertex.
102 corner_id = table->SwingRight(corner_id);
103 if (corner_id == start_corner_id) {
104 corner_id = kInvalidCornerIndex;
105 }
106 }
107 const int dst_offset = p * num_components;
108 if (num_parallelograms == 0) {
109 // No parallelogram was valid.
110 // We use the last encoded point as a reference.
111 const int src_offset = (p - 1) * num_components;
112 this->transform().ComputeCorrection(
113 in_data + dst_offset, in_data + src_offset, out_corr + dst_offset);
114 } else {
115 // Compute the correction from the predicted value.
116 for (int c = 0; c < num_components; ++c) {
117 pred_vals[c] /= num_parallelograms;
118 }
119 this->transform().ComputeCorrection(in_data + dst_offset, pred_vals.get(),
120 out_corr + dst_offset);
121 }
122 }
123 // First element is always fixed because it cannot be predicted.
124 for (int i = 0; i < num_components; ++i) {
125 pred_vals[i] = static_cast<DataTypeT>(0);
126 }
127 this->transform().ComputeCorrection(in_data, pred_vals.get(), out_corr);
128 return true;
129}
130
131} // namespace draco
132
133#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_MULTI_PARALLELOGRAM_ENCODER_H_
MeshPredictionSchemeEncoder(const PointAttribute *attribute, const TransformT &transform, const MeshDataT &mesh_data)
Definition mesh_prediction_scheme_encoder.h:31
const MeshData & mesh_data() const
Definition mesh_prediction_scheme_encoder.h:38
typename MeshDataT::CornerTable CornerTable
Definition mesh_prediction_scheme_multi_parallelogram_encoder.h:36
MeshPredictionSchemeMultiParallelogramEncoder(const PointAttribute *attribute, const TransformT &transform, const MeshDataT &mesh_data)
Definition mesh_prediction_scheme_multi_parallelogram_encoder.h:42
bool IsInitialized() const override
Definition mesh_prediction_scheme_multi_parallelogram_encoder.h:55
MeshPredictionSchemeMultiParallelogramEncoder(const PointAttribute *attribute)
Definition mesh_prediction_scheme_multi_parallelogram_encoder.h:38
typename PredictionSchemeEncoder< DataTypeT, TransformT >::CorrType CorrType
Definition mesh_prediction_scheme_multi_parallelogram_encoder.h:34
bool ComputeCorrectionValues(const DataTypeT *in_data, CorrType *out_corr, int size, int num_components, const PointIndex *entry_to_point_id_map) override
Definition mesh_prediction_scheme_multi_parallelogram_encoder.h:63
PredictionSchemeMethod GetPredictionMethod() const override
Definition mesh_prediction_scheme_multi_parallelogram_encoder.h:51
Definition point_attribute.h:33
const PointAttribute * attribute() const
Definition prediction_scheme_encoder.h:79
Transform::CorrType CorrType
Definition prediction_scheme_encoder.h:41
const Transform & transform() const
Definition prediction_scheme_encoder.h:80
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
Definition GameApi_pl.cc:29382