GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
prediction_scheme_normal_octahedron_canonicalized_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_NORMAL_OCTAHEDRON_CANONICALIZED_ENCODING_TRANSFORM_H_
16#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_NORMAL_OCTAHEDRON_CANONICALIZED_ENCODING_TRANSFORM_H_
17
18#include <cmath>
19
23#include "draco/core/macros.h"
24#include "draco/core/vector_d.h"
25
26namespace draco {
27
28// The transform works on octahedral coordinates for normals. The square is
29// subdivided into four inner triangles (diamond) and four outer triangles. The
30// inner triangles are associated with the upper part of the octahedron and the
31// outer triangles are associated with the lower part.
32// Given a prediction value P and the actual value Q that should be encoded,
33// this transform first checks if P is outside the diamond. If so, the outer
34// triangles are flipped towards the inside and vice versa. Then it checks if p
35// is in the bottom left quadrant. If it is not, it rotates p and q accordingly.
36// The actual correction value is then based on the mapped and rotated P and Q
37// values. The inversion tends to result in shorter correction vectors and the
38// rotation makes it so that all long correction values are positive, reducing
39// the possible value range of the correction values and increasing the
40// occurrences of positive large correction values, which helps the entropy
41// encoder. This is possible since P is also known by the decoder, see also
42// ComputeCorrection and ComputeOriginalValue functions.
43// Note that the tile is not periodic, which implies that the outer edges can
44// not be identified, which requires us to use an odd number of values on each
45// axis.
46// DataTypeT is expected to be some integral type.
47//
48template <typename DataTypeT>
51 DataTypeT> {
52 public:
56 typedef DataTypeT CorrType;
57 typedef DataTypeT DataType;
58
59 // We expect the mod value to be of the form 2^b-1.
63
64 // Dummy function to fulfill concept.
65 void Init(const DataTypeT *orig_data, int size, int num_components) {}
66
68 buffer->Encode(this->max_quantized_value());
69 buffer->Encode(this->center_value());
70 return true;
71 }
72
73 inline void ComputeCorrection(const DataType *orig_vals,
74 const DataType *pred_vals,
75 CorrType *out_corr_vals) const {
76 DRACO_DCHECK_LE(pred_vals[0], this->center_value() * 2);
77 DRACO_DCHECK_LE(pred_vals[1], this->center_value() * 2);
78 DRACO_DCHECK_LE(orig_vals[0], this->center_value() * 2);
79 DRACO_DCHECK_LE(orig_vals[1], this->center_value() * 2);
80 DRACO_DCHECK_LE(0, pred_vals[0]);
81 DRACO_DCHECK_LE(0, pred_vals[1]);
82 DRACO_DCHECK_LE(0, orig_vals[0]);
83 DRACO_DCHECK_LE(0, orig_vals[1]);
84
85 const Point2 orig = Point2(orig_vals[0], orig_vals[1]);
86 const Point2 pred = Point2(pred_vals[0], pred_vals[1]);
87 const Point2 corr = ComputeCorrection(orig, pred);
88
89 out_corr_vals[0] = corr[0];
90 out_corr_vals[1] = corr[1];
91 }
92
93 private:
94 Point2 ComputeCorrection(Point2 orig, Point2 pred) const {
95 const Point2 t(this->center_value(), this->center_value());
96 orig = orig - t;
97 pred = pred - t;
98 if (!this->IsInDiamond(pred[0], pred[1])) {
99 this->InvertDiamond(&orig[0], &orig[1]);
100 this->InvertDiamond(&pred[0], &pred[1]);
101 }
102 if (!this->IsInBottomLeft(pred)) {
103 const int32_t rotation_count = this->GetRotationCount(pred);
104 orig = this->RotatePoint(orig, rotation_count);
105 pred = this->RotatePoint(pred, rotation_count);
106 }
107 Point2 corr = orig - pred;
108 corr[0] = this->MakePositive(corr[0]);
109 corr[1] = this->MakePositive(corr[1]);
110 return corr;
111 }
112};
113
114} // namespace draco
115
116#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_NORMAL_OCTAHEDRON_CANONICALIZED_ENCODING_TRANSFORM_H_
Definition encoder_buffer.h:29
bool Encode(const T &data)
Definition encoder_buffer.h:60
bool EncodeTransformData(EncoderBuffer *buffer)
Definition prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h:67
DataTypeT CorrType
Definition prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h:56
void Init(const DataTypeT *orig_data, int size, int num_components)
Definition prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h:65
PredictionSchemeNormalOctahedronCanonicalizedEncodingTransform(DataType max_quantized_value)
Definition prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h:60
void ComputeCorrection(const DataType *orig_vals, const DataType *pred_vals, CorrType *out_corr_vals) const
Definition prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h:73
PredictionSchemeNormalOctahedronCanonicalizedTransformBase< DataTypeT > Base
Definition prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h:54
VectorD< DataTypeT, 2 > Point2
Definition prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h:55
DataTypeT DataType
Definition prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h:57
PredictionSchemeNormalOctahedronCanonicalizedTransformBase()
Definition prediction_scheme_normal_octahedron_canonicalized_transform_base.h:40
Point2 RotatePoint(Point2 p, int32_t rotation_count) const
Definition prediction_scheme_normal_octahedron_canonicalized_transform_base.h:79
int32_t GetRotationCount(Point2 pred) const
Definition prediction_scheme_normal_octahedron_canonicalized_transform_base.h:50
bool IsInBottomLeft(const Point2 &p) const
Definition prediction_scheme_normal_octahedron_canonicalized_transform_base.h:92
void InvertDiamond(DataTypeT *s, DataTypeT *t) const
Definition prediction_scheme_normal_octahedron_transform_base.h:73
DataTypeT max_quantized_value() const
Definition prediction_scheme_normal_octahedron_transform_base.h:51
DataTypeT center_value() const
Definition prediction_scheme_normal_octahedron_transform_base.h:54
bool IsInDiamond(DataTypeT s, DataTypeT t) const
Definition prediction_scheme_normal_octahedron_transform_base.h:70
int32_t MakePositive(int32_t x) const
Definition prediction_scheme_normal_octahedron_transform_base.h:80
Definition vector_d.h:30
#define DRACO_DCHECK_LE(a, b)
Definition macros.h:85
n< br > font size
Definition meshpage.php:3536
Definition attribute_octahedron_transform.cc:21