blob: 064e1b44fe13a0837fc24a499200c7cc4823a457 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
// Copyright 2016 The Draco Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_DECODER_H_
#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_DECODER_H_
#include <type_traits>
#include "draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_interface.h"
#include "draco/compression/attributes/prediction_schemes/prediction_scheme_decoding_transform.h"
// Prediction schemes can be used during encoding and decoding of vertex
// attributes to predict attribute values based on the previously
// encoded/decoded data. The differences between the original and predicted
// attribute values are used to compute correction values that can be usually
// encoded with fewer bits compared to the original data.
namespace draco {
// Abstract base class for typed prediction schemes. It provides basic access
// to the encoded attribute and to the supplied prediction transform.
template <typename DataTypeT,
class TransformT =
PredictionSchemeDecodingTransform<DataTypeT, DataTypeT>>
class PredictionSchemeDecoder : public PredictionSchemeTypedDecoderInterface<
DataTypeT, typename TransformT::CorrType> {
public:
typedef DataTypeT DataType;
typedef TransformT Transform;
// Correction type needs to be defined in the prediction transform class.
typedef typename Transform::CorrType CorrType;
explicit PredictionSchemeDecoder(const PointAttribute *attribute)
: PredictionSchemeDecoder(attribute, Transform()) {}
PredictionSchemeDecoder(const PointAttribute *attribute,
const Transform &transform)
: attribute_(attribute), transform_(transform) {}
bool DecodePredictionData(DecoderBuffer *buffer) override {
if (!transform_.DecodeTransformData(buffer)) {
return false;
}
return true;
}
const PointAttribute *GetAttribute() const override { return attribute(); }
// Returns the number of parent attributes that are needed for the prediction.
int GetNumParentAttributes() const override { return 0; }
// Returns the type of each of the parent attribute.
GeometryAttribute::Type GetParentAttributeType(int /* i */) const override {
return GeometryAttribute::INVALID;
}
// Sets the required parent attribute.
bool SetParentAttribute(const PointAttribute * /* att */) override {
return false;
}
bool AreCorrectionsPositive() override {
return transform_.AreCorrectionsPositive();
}
PredictionSchemeTransformType GetTransformType() const override {
return transform_.GetType();
}
protected:
inline const PointAttribute *attribute() const { return attribute_; }
inline const Transform &transform() const { return transform_; }
inline Transform &transform() { return transform_; }
private:
const PointAttribute *attribute_;
Transform transform_;
};
} // namespace draco
#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_DECODER_H_
|