GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
sequential_attribute_encoder.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_SEQUENTIAL_ATTRIBUTE_ENCODER_H_
16#define DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_ATTRIBUTE_ENCODER_H_
17
20
21namespace draco {
22
23// A base class for encoding attribute values of a single attribute using a
24// given sequence of point ids. The default implementation encodes all attribute
25// values directly to the buffer but derived classes can perform any custom
26// encoding (such as quantization) by overriding the EncodeValues() method.
28 public:
30 virtual ~SequentialAttributeEncoder() = default;
31
32 // Method that can be used for custom initialization of an attribute encoder,
33 // such as creation of prediction schemes and initialization of attribute
34 // encoder dependencies.
35 // |encoder| is the parent PointCloudEncoder,
36 // |attribute_id| is the id of the attribute that is being encoded by this
37 // encoder.
38 // This method is automatically called by the PointCloudEncoder after all
39 // attribute encoders are created and it should not be called explicitly from
40 // other places.
41 virtual bool Init(PointCloudEncoder *encoder, int attribute_id);
42
43 // Initialization for a specific attribute. This can be used mostly for
44 // standalone encoding of an attribute without an PointCloudEncoder.
46
47 // Transforms attribute data into format that is going to be encoded
48 // losslessly. The transform itself can be lossy.
50 const std::vector<PointIndex> &point_ids);
51
52 // Performs lossless encoding of the transformed attribute data.
53 virtual bool EncodePortableAttribute(const std::vector<PointIndex> &point_ids,
54 EncoderBuffer *out_buffer);
55
56 // Encodes any data related to the portable attribute transform.
57 virtual bool EncodeDataNeededByPortableTransform(EncoderBuffer *out_buffer);
58
59 virtual bool IsLossyEncoder() const { return false; }
60
61 int NumParentAttributes() const {
62 return static_cast<int>(parent_attributes_.size());
63 }
64 int GetParentAttributeId(int i) const { return parent_attributes_[i]; }
65
67 if (portable_attribute_ != nullptr) {
68 return portable_attribute_.get();
69 }
70 return attribute();
71 }
72
73 // Called when this attribute encoder becomes a parent encoder of another
74 // encoder.
76
77 virtual uint8_t GetUniqueId() const {
79 }
80
81 const PointAttribute *attribute() const { return attribute_; }
82 int attribute_id() const { return attribute_id_; }
83 PointCloudEncoder *encoder() const { return encoder_; }
84
85 protected:
86 // Should be used to initialize newly created prediction scheme.
87 // Returns false when the initialization failed (in which case the scheme
88 // cannot be used).
90
91 // Sets parent attributes for a given prediction scheme. Must be called
92 // after all prediction schemes are initialized, but before the prediction
93 // scheme is used.
96
97 // Encodes all attribute values in the specified order. Should be overridden
98 // for specialized encoders.
99 virtual bool EncodeValues(const std::vector<PointIndex> &point_ids,
100 EncoderBuffer *out_buffer);
101
102 bool is_parent_encoder() const { return is_parent_encoder_; }
103
104 void SetPortableAttribute(std::unique_ptr<PointAttribute> att) {
105 portable_attribute_ = std::move(att);
106 }
107
108 // Returns a mutable attribute that should be filled by derived encoders with
109 // the transformed version of the attribute data. To get a public const
110 // version, use the GetPortableAttribute() method.
111 PointAttribute *portable_attribute() { return portable_attribute_.get(); }
112
113 private:
114 PointCloudEncoder *encoder_;
115 const PointAttribute *attribute_;
116 int attribute_id_;
117
118 // List of attribute encoders that need to be encoded before this attribute.
119 // E.g. The parent attributes may be used to predict values used by this
120 // attribute encoder.
121 std::vector<int32_t> parent_attributes_;
122
123 bool is_parent_encoder_;
124
125 // Attribute that stores transformed data from the source attribute after it
126 // is processed through the ApplyTransform() method. Attribute data stored
127 // within this attribute is guaranteed to be encoded losslessly and it can be
128 // safely used for prediction of other attributes.
129 std::unique_ptr<PointAttribute> portable_attribute_;
130};
131
132} // namespace draco
133
134#endif // DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_ATTRIBUTE_ENCODER_H_
Definition encoder_buffer.h:29
Definition point_attribute.h:33
Definition point_cloud_encoder.h:29
Definition prediction_scheme_interface.h:27
virtual bool IsLossyEncoder() const
Definition sequential_attribute_encoder.h:59
virtual bool TransformAttributeToPortableFormat(const std::vector< PointIndex > &point_ids)
Definition sequential_attribute_encoder.cc:40
virtual ~SequentialAttributeEncoder()=default
int NumParentAttributes() const
Definition sequential_attribute_encoder.h:61
const PointAttribute * GetPortableAttribute() const
Definition sequential_attribute_encoder.h:66
virtual bool EncodePortableAttribute(const std::vector< PointIndex > &point_ids, EncoderBuffer *out_buffer)
Definition sequential_attribute_encoder.cc:46
void SetPortableAttribute(std::unique_ptr< PointAttribute > att)
Definition sequential_attribute_encoder.h:104
PointCloudEncoder * encoder() const
Definition sequential_attribute_encoder.h:83
PointAttribute * portable_attribute()
Definition sequential_attribute_encoder.h:111
int attribute_id() const
Definition sequential_attribute_encoder.h:82
virtual bool Init(PointCloudEncoder *encoder, int attribute_id)
Definition sequential_attribute_encoder.cc:25
virtual bool SetPredictionSchemeParentAttributes(PredictionSchemeInterface *ps)
Definition sequential_attribute_encoder.cc:93
void MarkParentAttribute()
Definition sequential_attribute_encoder.cc:75
const PointAttribute * attribute() const
Definition sequential_attribute_encoder.h:81
bool is_parent_encoder() const
Definition sequential_attribute_encoder.h:102
virtual bool EncodeDataNeededByPortableTransform(EncoderBuffer *out_buffer)
Definition sequential_attribute_encoder.cc:55
int GetParentAttributeId(int i) const
Definition sequential_attribute_encoder.h:64
virtual uint8_t GetUniqueId() const
Definition sequential_attribute_encoder.h:77
virtual bool InitializeStandalone(PointAttribute *attribute)
Definition sequential_attribute_encoder.cc:33
virtual bool EncodeValues(const std::vector< PointIndex > &point_ids, EncoderBuffer *out_buffer)
Definition sequential_attribute_encoder.cc:61
virtual bool InitPredictionScheme(PredictionSchemeInterface *ps)
Definition sequential_attribute_encoder.cc:79
SequentialAttributeEncoder()
Definition sequential_attribute_encoder.cc:19
Definition attribute_octahedron_transform.cc:21
@ SEQUENTIAL_ATTRIBUTE_ENCODER_GENERIC
Definition compression_shared.h:73