GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
prediction_scheme_wrap_encoding_transform.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_PREDICTION_SCHEME_WRAP_ENCODING_TRANSFORM_H_
16#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_WRAP_ENCODING_TRANSFORM_H_
17
20
21namespace draco {
22
23// PredictionSchemeWrapEncodingTransform wraps input values using the wrapping
24// scheme described in: prediction_scheme_wrap_transform_base.h .
25template <typename DataTypeT, typename CorrTypeT = DataTypeT>
27 : public PredictionSchemeWrapTransformBase<DataTypeT> {
28 public:
29 typedef CorrTypeT CorrType;
31
32 void Init(const DataTypeT *orig_data, int size, int num_components) {
34 // Go over the original values and compute the bounds.
35 if (size == 0) {
36 return;
37 }
38 DataTypeT min_value = orig_data[0];
39 DataTypeT max_value = min_value;
40 for (int i = 1; i < size; ++i) {
41 if (orig_data[i] < min_value) {
42 min_value = orig_data[i];
43 } else if (orig_data[i] > max_value) {
44 max_value = orig_data[i];
45 }
46 }
47 this->set_min_value(min_value);
48 this->set_max_value(max_value);
50 }
51
52 // Computes the corrections based on the input original value and the
53 // predicted value. Out of bound correction values are wrapped around the max
54 // range of input values.
55 inline void ComputeCorrection(const DataTypeT *original_vals,
56 const DataTypeT *predicted_vals,
57 CorrTypeT *out_corr_vals) const {
58 for (int i = 0; i < this->num_components(); ++i) {
59 predicted_vals = this->ClampPredictedValue(predicted_vals);
60 out_corr_vals[i] = original_vals[i] - predicted_vals[i];
61 // Wrap around if needed.
62 DataTypeT &corr_val = out_corr_vals[i];
63 if (corr_val < this->min_correction()) {
64 corr_val += this->max_dif();
65 } else if (corr_val > this->max_correction()) {
66 corr_val -= this->max_dif();
67 }
68 }
69 }
70
72 // Store the input value range as it is needed by the decoder.
73 buffer->Encode(this->min_value());
74 buffer->Encode(this->max_value());
75 return true;
76 }
77};
78
79} // namespace draco
80
81#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_WRAP_ENCODING_TRANSFORM_H_
Definition encoder_buffer.h:29
bool Encode(const T &data)
Definition encoder_buffer.h:60
PredictionSchemeWrapEncodingTransform()
Definition prediction_scheme_wrap_encoding_transform.h:30
void Init(const DataTypeT *orig_data, int size, int num_components)
Definition prediction_scheme_wrap_encoding_transform.h:32
CorrTypeT CorrType
Definition prediction_scheme_wrap_encoding_transform.h:29
void ComputeCorrection(const DataTypeT *original_vals, const DataTypeT *predicted_vals, CorrTypeT *out_corr_vals) const
Definition prediction_scheme_wrap_encoding_transform.h:55
bool EncodeTransformData(EncoderBuffer *buffer)
Definition prediction_scheme_wrap_encoding_transform.h:71
void Init(int num_components)
Definition prediction_scheme_wrap_transform_base.h:55
PredictionSchemeWrapTransformBase()
Definition prediction_scheme_wrap_transform_base.h:43
DataTypeT min_value() const
Definition prediction_scheme_wrap_transform_base.h:99
DataTypeT min_correction() const
Definition prediction_scheme_wrap_transform_base.h:104
const DataTypeT * ClampPredictedValue(const DataTypeT *predicted_val) const
Definition prediction_scheme_wrap_transform_base.h:62
void set_max_value(const DataTypeT &v)
Definition prediction_scheme_wrap_transform_base.h:102
bool InitCorrectionBounds()
Definition prediction_scheme_wrap_transform_base.h:83
DataTypeT max_dif() const
Definition prediction_scheme_wrap_transform_base.h:103
int num_components() const
Definition prediction_scheme_wrap_transform_base.h:98
void set_min_value(const DataTypeT &v)
Definition prediction_scheme_wrap_transform_base.h:100
DataTypeT max_correction() const
Definition prediction_scheme_wrap_transform_base.h:105
DataTypeT max_value() const
Definition prediction_scheme_wrap_transform_base.h:101
n< br > font size
Definition meshpage.php:3536
Definition attribute_octahedron_transform.cc:21