GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
attributes_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_ATTRIBUTES_ENCODER_H_
16#define DRACO_COMPRESSION_ATTRIBUTES_ATTRIBUTES_ENCODER_H_
17
21
22namespace draco {
23
25
26// Base class for encoding one or more attributes of a PointCloud (or other
27// geometry). This base class provides only the basic interface that is used
28// by the PointCloudEncoder.
30 public:
32 // Constructs an attribute encoder associated with a given point attribute.
33 explicit AttributesEncoder(int point_attrib_id);
34 virtual ~AttributesEncoder() = default;
35
36 // Called after all attribute encoders are created. It can be used to perform
37 // any custom initialization, including setting up attribute dependencies.
38 // Note: no data should be encoded in this function, because the decoder may
39 // process encoders in a different order from the decoder.
40 virtual bool Init(PointCloudEncoder *encoder, const PointCloud *pc);
41
42 // Encodes data needed by the target attribute decoder.
43 virtual bool EncodeAttributesEncoderData(EncoderBuffer *out_buffer);
44
45 // Returns a unique identifier of the given encoder type, that is used during
46 // decoding to construct the corresponding attribute decoder.
47 virtual uint8_t GetUniqueId() const = 0;
48
49 // Encode attribute data to the target buffer.
50 virtual bool EncodeAttributes(EncoderBuffer *out_buffer) {
52 return false;
53 }
54 if (!EncodePortableAttributes(out_buffer)) {
55 return false;
56 }
57 // Encode data needed by portable transforms after the attribute is encoded.
58 // This corresponds to the order in which the data is going to be decoded by
59 // the decoder.
60 if (!EncodeDataNeededByPortableTransforms(out_buffer)) {
61 return false;
62 }
63 return true;
64 }
65
66 // Returns the number of attributes that need to be encoded before the
67 // specified attribute is encoded.
68 // Note that the attribute is specified by its point attribute id.
69 virtual int NumParentAttributes(int32_t /* point_attribute_id */) const {
70 return 0;
71 }
72
73 virtual int GetParentAttributeId(int32_t /* point_attribute_id */,
74 int32_t /* parent_i */) const {
75 return -1;
76 }
77
78 // Marks a given attribute as a parent of another attribute.
79 virtual bool MarkParentAttribute(int32_t /* point_attribute_id */) {
80 return false;
81 }
82
83 // Returns an attribute containing data processed by the attribute transform.
84 // (see TransformToPortableFormat() method). This data is guaranteed to be
85 // encoded losslessly and it can be safely used for predictors.
87 int32_t /* point_attribute_id */) {
88 return nullptr;
89 }
90
91 void AddAttributeId(int32_t id) {
92 point_attribute_ids_.push_back(id);
93 if (id >= static_cast<int32_t>(point_attribute_to_local_id_map_.size())) {
94 point_attribute_to_local_id_map_.resize(id + 1, -1);
95 }
96 point_attribute_to_local_id_map_[id] =
97 static_cast<int32_t>(point_attribute_ids_.size()) - 1;
98 }
99
100 // Sets new attribute point ids (replacing the existing ones).
101 void SetAttributeIds(const std::vector<int32_t> &point_attribute_ids) {
102 point_attribute_ids_.clear();
103 point_attribute_to_local_id_map_.clear();
104 for (int32_t att_id : point_attribute_ids) {
105 AddAttributeId(att_id);
106 }
107 }
108
109 int32_t GetAttributeId(int i) const { return point_attribute_ids_[i]; }
110 uint32_t num_attributes() const {
111 return static_cast<uint32_t>(point_attribute_ids_.size());
112 }
113 PointCloudEncoder *encoder() const { return point_cloud_encoder_; }
114
115 protected:
116 // Transforms the input attribute data into a form that should be losslessly
117 // encoded (transform itself can be lossy).
118 virtual bool TransformAttributesToPortableFormat() { return true; }
119
120 // Losslessly encodes data of all portable attributes.
121 // Precondition: All attributes must have been transformed into portable
122 // format at this point (see TransformAttributesToPortableFormat() method).
123 virtual bool EncodePortableAttributes(EncoderBuffer *out_buffer) = 0;
124
125 // Encodes any data needed to revert the transform to portable format for each
126 // attribute (e.g. data needed for dequantization of quantized values).
128 return true;
129 }
130
131 int32_t GetLocalIdForPointAttribute(int32_t point_attribute_id) const {
132 const int id_map_size =
133 static_cast<int>(point_attribute_to_local_id_map_.size());
134 if (point_attribute_id >= id_map_size) {
135 return -1;
136 }
137 return point_attribute_to_local_id_map_[point_attribute_id];
138 }
139
140 private:
141 // List of attribute ids that need to be encoded with this encoder.
142 std::vector<int32_t> point_attribute_ids_;
143
144 // Map between point attribute id and the local id (i.e., the inverse of the
145 // |point_attribute_ids_|.
146 std::vector<int32_t> point_attribute_to_local_id_map_;
147
148 PointCloudEncoder *point_cloud_encoder_;
149 const PointCloud *point_cloud_;
150};
151
152} // namespace draco
153
154#endif // DRACO_COMPRESSION_ATTRIBUTES_ATTRIBUTES_ENCODER_H_
virtual bool TransformAttributesToPortableFormat()
Definition attributes_encoder.h:118
int32_t GetAttributeId(int i) const
Definition attributes_encoder.h:109
virtual bool EncodeAttributes(EncoderBuffer *out_buffer)
Definition attributes_encoder.h:50
virtual bool EncodeDataNeededByPortableTransforms(EncoderBuffer *out_buffer)
Definition attributes_encoder.h:127
virtual int GetParentAttributeId(int32_t, int32_t) const
Definition attributes_encoder.h:73
virtual bool EncodePortableAttributes(EncoderBuffer *out_buffer)=0
void SetAttributeIds(const std::vector< int32_t > &point_attribute_ids)
Definition attributes_encoder.h:101
PointCloudEncoder * encoder() const
Definition attributes_encoder.h:113
AttributesEncoder()
Definition attributes_encoder.cc:22
virtual bool Init(PointCloudEncoder *encoder, const PointCloud *pc)
Definition attributes_encoder.cc:30
void AddAttributeId(int32_t id)
Definition attributes_encoder.h:91
virtual int NumParentAttributes(int32_t) const
Definition attributes_encoder.h:69
uint32_t num_attributes() const
Definition attributes_encoder.h:110
virtual bool EncodeAttributesEncoderData(EncoderBuffer *out_buffer)
Definition attributes_encoder.cc:36
virtual const PointAttribute * GetPortableAttribute(int32_t)
Definition attributes_encoder.h:86
virtual uint8_t GetUniqueId() const =0
int32_t GetLocalIdForPointAttribute(int32_t point_attribute_id) const
Definition attributes_encoder.h:131
virtual ~AttributesEncoder()=default
virtual bool MarkParentAttribute(int32_t)
Definition attributes_encoder.h:79
Definition encoder_buffer.h:29
Definition point_attribute.h:33
Definition point_cloud_encoder.h:29
Definition point_cloud.h:29
Definition attribute_octahedron_transform.cc:21