GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
mesh_prediction_scheme_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_PARALLELOGRAM_ENCODER_H_
16#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_PARALLELOGRAM_ENCODER_H_
17
20
21namespace draco {
22
23// Parallelogram prediction predicts an attribute value V from three vertices
24// on the opposite face to the predicted vertex. The values on the three
25// vertices are used to construct a parallelogram V' = O - A - B, where O is the
26// value on the opposite vertex, and A, B are values on the shared vertices:
27// V
28// / \
29// / \
30// / \
31// A-------B
32// \ /
33// \ /
34// \ /
35// O
36//
37template <typename DataTypeT, class TransformT, class MeshDataT>
39 : public MeshPredictionSchemeEncoder<DataTypeT, TransformT, MeshDataT> {
40 public:
41 using CorrType =
43 using CornerTable = typename MeshDataT::CornerTable;
46 : MeshPredictionSchemeEncoder<DataTypeT, TransformT, MeshDataT>(
47 attribute) {}
49 const TransformT &transform,
50 const MeshDataT &mesh_data)
51 : MeshPredictionSchemeEncoder<DataTypeT, TransformT, MeshDataT>(
53
55 const DataTypeT *in_data, CorrType *out_corr, int size,
56 int num_components, const PointIndex *entry_to_point_id_map) override;
60
61 bool IsInitialized() const override {
62 return this->mesh_data().IsInitialized();
63 }
64};
65
66template <typename DataTypeT, class TransformT, class MeshDataT>
67bool MeshPredictionSchemeParallelogramEncoder<DataTypeT, TransformT,
68 MeshDataT>::
69 ComputeCorrectionValues(const DataTypeT *in_data, CorrType *out_corr,
70 int size, int num_components,
71 const PointIndex * /* entry_to_point_id_map */) {
72 this->transform().Init(in_data, size, num_components);
73 // For storage of prediction values (already initialized to zero).
74 std::unique_ptr<DataTypeT[]> pred_vals(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 const CornerTable *const table = this->mesh_data().corner_table();
79 const std::vector<int32_t> *const vertex_to_data_map =
80 this->mesh_data().vertex_to_data_map();
81 for (int p =
82 static_cast<int>(this->mesh_data().data_to_corner_map()->size() - 1);
83 p > 0; --p) {
84 const CornerIndex corner_id = this->mesh_data().data_to_corner_map()->at(p);
85 const int dst_offset = p * num_components;
86 if (!ComputeParallelogramPrediction(p, corner_id, table,
87 *vertex_to_data_map, in_data,
88 num_components, pred_vals.get())) {
89 // Parallelogram could not be computed, Possible because some of the
90 // vertices are not valid (not encoded yet).
91 // We use the last encoded point as a reference (delta coding).
92 const int src_offset = (p - 1) * num_components;
93 this->transform().ComputeCorrection(
94 in_data + dst_offset, in_data + src_offset, out_corr + dst_offset);
95 } else {
96 // Apply the parallelogram prediction.
97 this->transform().ComputeCorrection(in_data + dst_offset, pred_vals.get(),
98 out_corr + dst_offset);
99 }
100 }
101 // First element is always fixed because it cannot be predicted.
102 for (int i = 0; i < num_components; ++i) {
103 pred_vals[i] = static_cast<DataTypeT>(0);
104 }
105 this->transform().ComputeCorrection(in_data, pred_vals.get(), out_corr);
106 return true;
107}
108
109} // namespace draco
110
111#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_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
bool IsInitialized() const override
Definition mesh_prediction_scheme_parallelogram_encoder.h:61
MeshPredictionSchemeParallelogramEncoder(const PointAttribute *attribute, const TransformT &transform, const MeshDataT &mesh_data)
Definition mesh_prediction_scheme_parallelogram_encoder.h:48
typename PredictionSchemeEncoder< DataTypeT, TransformT >::CorrType CorrType
Definition mesh_prediction_scheme_parallelogram_encoder.h:41
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_parallelogram_encoder.h:69
PredictionSchemeMethod GetPredictionMethod() const override
Definition mesh_prediction_scheme_parallelogram_encoder.h:57
MeshPredictionSchemeParallelogramEncoder(const PointAttribute *attribute)
Definition mesh_prediction_scheme_parallelogram_encoder.h:44
typename MeshDataT::CornerTable CornerTable
Definition mesh_prediction_scheme_parallelogram_encoder.h:43
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_PARALLELOGRAM
Definition compression_shared.h:86
Definition GameApi_pl.cc:29382