GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
sequential_attribute_encoders_controller.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_ENCODERS_CONTROLLER_H_
16#define DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_ATTRIBUTE_ENCODERS_CONTROLLER_H_
17
21
22namespace draco {
23
24// A basic implementation of an attribute encoder that can be used to encode
25// an arbitrary set of attributes. The encoder creates a sequential attribute
26// encoder for each encoded attribute (see sequential_attribute_encoder.h) and
27// then it encodes all attribute values in an order defined by a point sequence
28// generated in the GeneratePointSequence() method. The default implementation
29// generates a linear sequence of all points, but derived classes can generate
30// any custom sequence.
32 public:
34 std::unique_ptr<PointsSequencer> sequencer);
36 std::unique_ptr<PointsSequencer> sequencer, int point_attrib_id);
37
38 bool Init(PointCloudEncoder *encoder, const PointCloud *pc) override;
39 bool EncodeAttributesEncoderData(EncoderBuffer *out_buffer) override;
40 bool EncodeAttributes(EncoderBuffer *buffer) override;
41 uint8_t GetUniqueId() const override { return BASIC_ATTRIBUTE_ENCODER; }
42
43 int NumParentAttributes(int32_t point_attribute_id) const override {
44 const int32_t loc_id = GetLocalIdForPointAttribute(point_attribute_id);
45 if (loc_id < 0) {
46 return 0;
47 }
48 return sequential_encoders_[loc_id]->NumParentAttributes();
49 }
50
51 int GetParentAttributeId(int32_t point_attribute_id,
52 int32_t parent_i) const override {
53 const int32_t loc_id = GetLocalIdForPointAttribute(point_attribute_id);
54 if (loc_id < 0) {
55 return -1;
56 }
57 return sequential_encoders_[loc_id]->GetParentAttributeId(parent_i);
58 }
59
60 bool MarkParentAttribute(int32_t point_attribute_id) override {
61 const int32_t loc_id = GetLocalIdForPointAttribute(point_attribute_id);
62 if (loc_id < 0) {
63 return false;
64 }
65 // Mark the attribute encoder as parent (even when if it is not created
66 // yet).
67 if (sequential_encoder_marked_as_parent_.size() <= loc_id) {
68 sequential_encoder_marked_as_parent_.resize(loc_id + 1, false);
69 }
70 sequential_encoder_marked_as_parent_[loc_id] = true;
71
72 if (sequential_encoders_.size() <= loc_id) {
73 return true; // Sequential encoders not generated yet.
74 }
75 sequential_encoders_[loc_id]->MarkParentAttribute();
76 return true;
77 }
78
80 int32_t point_attribute_id) override {
81 const int32_t loc_id = GetLocalIdForPointAttribute(point_attribute_id);
82 if (loc_id < 0) {
83 return nullptr;
84 }
85 return sequential_encoders_[loc_id]->GetPortableAttribute();
86 }
87
88 protected:
90 bool EncodePortableAttributes(EncoderBuffer *out_buffer) override;
91 bool EncodeDataNeededByPortableTransforms(EncoderBuffer *out_buffer) override;
92
93 // Creates all sequential encoders (one for each attribute associated with the
94 // encoder).
95 virtual bool CreateSequentialEncoders();
96
97 // Create a sequential encoder for a given attribute based on the attribute
98 // type
99 // and the provided encoder options.
100 virtual std::unique_ptr<SequentialAttributeEncoder> CreateSequentialEncoder(
101 int i);
102
103 private:
104 std::vector<std::unique_ptr<SequentialAttributeEncoder>> sequential_encoders_;
105
106 // Flag for each sequential attribute encoder indicating whether it was marked
107 // as parent attribute or not.
108 std::vector<bool> sequential_encoder_marked_as_parent_;
109 std::vector<PointIndex> point_ids_;
110 std::unique_ptr<PointsSequencer> sequencer_;
111};
112
113} // namespace draco
114
115#endif // DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_ATTRIBUTE_ENCODERS_CONTROLLER_H_
PointCloudEncoder * encoder() const
Definition attributes_encoder.h:113
AttributesEncoder()
Definition attributes_encoder.cc:22
int32_t GetLocalIdForPointAttribute(int32_t point_attribute_id) const
Definition attributes_encoder.h:131
Definition encoder_buffer.h:29
Definition point_attribute.h:33
Definition point_cloud_encoder.h:29
Definition point_cloud.h:29
uint8_t GetUniqueId() const override
Definition sequential_attribute_encoders_controller.h:41
const PointAttribute * GetPortableAttribute(int32_t point_attribute_id) override
Definition sequential_attribute_encoders_controller.h:79
bool EncodePortableAttributes(EncoderBuffer *out_buffer) override
Definition sequential_attribute_encoders_controller.cc:81
virtual bool CreateSequentialEncoders()
Definition sequential_attribute_encoders_controller.cc:103
bool MarkParentAttribute(int32_t point_attribute_id) override
Definition sequential_attribute_encoders_controller.h:60
bool Init(PointCloudEncoder *encoder, const PointCloud *pc) override
Definition sequential_attribute_encoders_controller.cc:32
bool TransformAttributesToPortableFormat() override
Definition sequential_attribute_encoders_controller.cc:71
bool EncodeDataNeededByPortableTransforms(EncoderBuffer *out_buffer) override
Definition sequential_attribute_encoders_controller.cc:93
bool EncodeAttributesEncoderData(EncoderBuffer *out_buffer) override
Definition sequential_attribute_encoders_controller.cc:50
bool EncodeAttributes(EncoderBuffer *buffer) override
Definition sequential_attribute_encoders_controller.cc:62
SequentialAttributeEncodersController(std::unique_ptr< PointsSequencer > sequencer)
Definition sequential_attribute_encoders_controller.cc:24
virtual std::unique_ptr< SequentialAttributeEncoder > CreateSequentialEncoder(int i)
Definition sequential_attribute_encoders_controller.cc:120
int GetParentAttributeId(int32_t point_attribute_id, int32_t parent_i) const override
Definition sequential_attribute_encoders_controller.h:51
int NumParentAttributes(int32_t point_attribute_id) const override
Definition sequential_attribute_encoders_controller.h:43
Definition attribute_octahedron_transform.cc:21
@ BASIC_ATTRIBUTE_ENCODER
Definition compression_shared.h:64