GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
prediction_scheme_normal_octahedron_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_ENCODING_TRANSFORM_H_
16#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_NORMAL_OCTAHEDRON_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. The actual
35// correction value is then based on the mapped P and Q values. This tends to
36// result in shorter correction vectors.
37// This is possible since the P value is also known by the decoder, see also
38// ComputeCorrection and ComputeOriginalValue functions.
39// Note that the tile is not periodic, which implies that the outer edges can
40// not be identified, which requires us to use an odd number of values on each
41// axis.
42// DataTypeT is expected to be some integral type.
43//
44template <typename DataTypeT>
47 public:
50 typedef DataTypeT CorrType;
51 typedef DataTypeT DataType;
52
53 // We expect the mod value to be of the form 2^b-1.
57
58 void Init(const DataTypeT *orig_data, int size, int num_components) {}
59
61 buffer->Encode(this->max_quantized_value());
62 return true;
63 }
64
65 inline void ComputeCorrection(const DataType *orig_vals,
66 const DataType *pred_vals,
67 CorrType *out_corr_vals) const {
68 DRACO_DCHECK_LE(pred_vals[0], this->center_value() * 2);
69 DRACO_DCHECK_LE(pred_vals[1], this->center_value() * 2);
70 DRACO_DCHECK_LE(orig_vals[0], this->center_value() * 2);
71 DRACO_DCHECK_LE(orig_vals[1], this->center_value() * 2);
72 DRACO_DCHECK_LE(0, pred_vals[0]);
73 DRACO_DCHECK_LE(0, pred_vals[1]);
74 DRACO_DCHECK_LE(0, orig_vals[0]);
75 DRACO_DCHECK_LE(0, orig_vals[1]);
76
77 const Point2 orig = Point2(orig_vals[0], orig_vals[1]);
78 const Point2 pred = Point2(pred_vals[0], pred_vals[1]);
79 const Point2 corr = ComputeCorrection(orig, pred);
80
81 out_corr_vals[0] = corr[0];
82 out_corr_vals[1] = corr[1];
83 }
84
85 private:
86 Point2 ComputeCorrection(Point2 orig, Point2 pred) const {
87 const Point2 t(this->center_value(), this->center_value());
88 orig = orig - t;
89 pred = pred - t;
90
91 if (!this->IsInDiamond(pred[0], pred[1])) {
92 this->InvertDiamond(&orig[0], &orig[1]);
93 this->InvertDiamond(&pred[0], &pred[1]);
94 }
95
96 Point2 corr = orig - pred;
97 corr[0] = this->MakePositive(corr[0]);
98 corr[1] = this->MakePositive(corr[1]);
99 return corr;
100 }
101};
102
103} // namespace draco
104
105#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_NORMAL_OCTAHEDRON_ENCODING_TRANSFORM_H_
Definition encoder_buffer.h:29
bool Encode(const T &data)
Definition encoder_buffer.h:60
VectorD< DataTypeT, 2 > Point2
Definition prediction_scheme_normal_octahedron_encoding_transform.h:49
bool EncodeTransformData(EncoderBuffer *buffer)
Definition prediction_scheme_normal_octahedron_encoding_transform.h:60
DataTypeT DataType
Definition prediction_scheme_normal_octahedron_encoding_transform.h:51
PredictionSchemeNormalOctahedronEncodingTransform(DataType max_quantized_value)
Definition prediction_scheme_normal_octahedron_encoding_transform.h:54
DataTypeT CorrType
Definition prediction_scheme_normal_octahedron_encoding_transform.h:50
void Init(const DataTypeT *orig_data, int size, int num_components)
Definition prediction_scheme_normal_octahedron_encoding_transform.h:58
PredictionSchemeNormalOctahedronTransformBase< DataTypeT > Base
Definition prediction_scheme_normal_octahedron_encoding_transform.h:48
void ComputeCorrection(const DataType *orig_vals, const DataType *pred_vals, CorrType *out_corr_vals) const
Definition prediction_scheme_normal_octahedron_encoding_transform.h:65
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
PredictionSchemeNormalOctahedronTransformBase()
Definition prediction_scheme_normal_octahedron_transform_base.h:37
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