GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
prediction_scheme_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_ENCODING_TRANSFORM_H_
16#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_ENCODING_TRANSFORM_H_
17
20
21namespace draco {
22
23// PredictionSchemeEncodingTransform is used to transform predicted values into
24// correction values.
25// CorrTypeT is the data type used for storing corrected values. It allows
26// transforms to store corrections into a different type or format compared to
27// the predicted data.
28template <typename DataTypeT, typename CorrTypeT>
30 public:
31 typedef CorrTypeT CorrType;
32 PredictionSchemeEncodingTransform() : num_components_(0) {}
33
37
38 // Performs any custom initialization of the transform for the encoder.
39 // |size| = total number of values in |orig_data| (i.e., number of entries *
40 // number of components).
41 void Init(const DataTypeT * /* orig_data */, int /* size */,
42 int num_components) {
43 num_components_ = num_components;
44 }
45
46 // Computes the corrections based on the input original values and the
47 // predicted values. The correction is always computed for all components
48 // of the input element. |val_id| is the id of the input value
49 // (i.e., element_id * num_components). The default implementation is equal to
50 // std::minus.
51 inline void ComputeCorrection(const DataTypeT *original_vals,
52 const DataTypeT *predicted_vals,
53 CorrTypeT *out_corr_vals) {
54 static_assert(std::is_same<DataTypeT, CorrTypeT>::value,
55 "For the default prediction transform, correction and input "
56 "data must be of the same type.");
57 for (int i = 0; i < num_components_; ++i) {
58 out_corr_vals[i] = original_vals[i] - predicted_vals[i];
59 }
60 }
61
62 // Encode any transform specific data.
63 bool EncodeTransformData(EncoderBuffer * /* buffer */) { return true; }
64
65 // Should return true if all corrected values are guaranteed to be positive.
66 bool AreCorrectionsPositive() const { return false; }
67
68 protected:
69 int num_components() const { return num_components_; }
70
71 private:
72 int num_components_;
73};
74
75} // namespace draco
76
77#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_ENCODING_TRANSFORM_H_
Definition encoder_buffer.h:29
void ComputeCorrection(const DataTypeT *original_vals, const DataTypeT *predicted_vals, CorrTypeT *out_corr_vals)
Definition prediction_scheme_encoding_transform.h:51
PredictionSchemeTransformType GetType() const
Definition prediction_scheme_encoding_transform.h:34
void Init(const DataTypeT *, int, int num_components)
Definition prediction_scheme_encoding_transform.h:41
bool AreCorrectionsPositive() const
Definition prediction_scheme_encoding_transform.h:66
int num_components() const
Definition prediction_scheme_encoding_transform.h:69
PredictionSchemeEncodingTransform()
Definition prediction_scheme_encoding_transform.h:32
bool EncodeTransformData(EncoderBuffer *)
Definition prediction_scheme_encoding_transform.h:63
CorrTypeT CorrType
Definition prediction_scheme_encoding_transform.h:31
Definition attribute_octahedron_transform.cc:21
PredictionSchemeTransformType
Definition compression_shared.h:96
@ PREDICTION_TRANSFORM_DELTA
Definition compression_shared.h:100