GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
point_cloud_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_POINT_CLOUD_POINT_CLOUD_ENCODER_H_
16#define DRACO_COMPRESSION_POINT_CLOUD_POINT_CLOUD_ENCODER_H_
17
22#include "draco/core/status.h"
24
25namespace draco {
26
27// Abstract base class for all point cloud and mesh encoders. It provides a
28// basic functionality that's shared between different encoders.
30 public:
32 virtual ~PointCloudEncoder() = default;
33
34 // Sets the point cloud that is going be encoded. Must be called before the
35 // Encode() method.
36 void SetPointCloud(const PointCloud &pc);
37
38 // The main entry point that encodes provided point cloud.
40
42
43 // Returns the unique identifier of the encoding method (such as Edgebreaker
44 // for mesh compression).
45 virtual uint8_t GetEncodingMethod() const = 0;
46
47 // Returns the number of points that were encoded during the last Encode()
48 // function call. Valid only if "store_number_of_encoded_points" flag was set
49 // in the provided EncoderOptions.
50 size_t num_encoded_points() const { return num_encoded_points_; }
51
53 return static_cast<int>(attributes_encoders_.size());
54 }
56 return attributes_encoders_[i].get();
57 }
58
59 // Adds a new attribute encoder, returning its id.
60 int AddAttributesEncoder(std::unique_ptr<AttributesEncoder> att_enc) {
61 attributes_encoders_.push_back(std::move(att_enc));
62 return static_cast<int>(attributes_encoders_.size() - 1);
63 }
64
65 // Marks one attribute as a parent of another attribute. Must be called after
66 // all attribute encoders are created (usually in the
67 // AttributeEncoder::Init() method).
68 bool MarkParentAttribute(int32_t parent_att_id);
69
70 // Returns an attribute containing portable version of the attribute data that
71 // is guaranteed to be encoded losslessly. This attribute can be used safely
72 // as predictor for other attributes.
73 const PointAttribute *GetPortableAttribute(int32_t point_attribute_id);
74
75 EncoderBuffer *buffer() { return buffer_; }
76 const EncoderOptions *options() const { return options_; }
77 const PointCloud *point_cloud() const { return point_cloud_; }
78
79 protected:
80 // Can be implemented by derived classes to perform any custom initialization
81 // of the encoder. Called in the Encode() method.
82 virtual bool InitializeEncoder() { return true; }
83
84 // Should be used to encode any encoder-specific data.
85 virtual bool EncodeEncoderData() { return true; }
86
87 // Encodes any global geometry data (such as the number of points).
88 virtual Status EncodeGeometryData() { return OkStatus(); }
89
90 // encode all attribute values. The attribute encoders are sorted to resolve
91 // any attribute dependencies and all the encoded data is stored into the
92 // |buffer_|.
93 // Returns false if the encoding failed.
94 virtual bool EncodePointAttributes();
95
96 // Generate attribute encoders that are going to be used for encoding
97 // point attribute data. Calls GenerateAttributesEncoder() for every attribute
98 // of the encoded PointCloud.
99 virtual bool GenerateAttributesEncoders();
100
101 // Creates attribute encoder for a specific point attribute. This function
102 // needs to be implemented by the derived classes. The derived classes need
103 // to either 1. Create a new attribute encoder and add it using the
104 // AddAttributeEncoder method, or 2. add the attribute to an existing
105 // attribute encoder (using AttributesEncoder::AddAttributeId() method).
106 virtual bool GenerateAttributesEncoder(int32_t att_id) = 0;
107
108 // Encodes any data that is necessary to recreate a given attribute encoder.
109 // Note: this is called in order in which the attribute encoders are going to
110 // be encoded.
111 virtual bool EncodeAttributesEncoderIdentifier(int32_t /* att_encoder_id */) {
112 return true;
113 }
114
115 // Encodes all the attribute data using the created attribute encoders.
116 virtual bool EncodeAllAttributes();
117
118 // Computes and sets the num_encoded_points_ for the encoder.
120
121 void set_num_encoded_points(size_t num_points) {
122 num_encoded_points_ = num_points;
123 }
124
125 private:
126 // Encodes Draco header that is the same for all encoders.
127 Status EncodeHeader();
128
129 // Encode metadata.
130 Status EncodeMetadata();
131
132 // Rearranges attribute encoders and their attributes to reflect the
133 // underlying attribute dependencies. This ensures that the attributes are
134 // encoded in the correct order (parent attributes before their children).
135 bool RearrangeAttributesEncoders();
136
137 const PointCloud *point_cloud_;
138 std::vector<std::unique_ptr<AttributesEncoder>> attributes_encoders_;
139
140 // Map between attribute id and encoder id.
141 std::vector<int32_t> attribute_to_encoder_map_;
142
143 // Encoding order of individual attribute encoders (i.e., the order in which
144 // they are processed during encoding that may be different from the order
145 // in which they were created because of attribute dependencies.
146 std::vector<int32_t> attributes_encoder_ids_order_;
147
148 // This buffer holds the final encoded data.
149 EncoderBuffer *buffer_;
150
151 const EncoderOptions *options_;
152
153 size_t num_encoded_points_;
154};
155
156} // namespace draco
157
158#endif // DRACO_COMPRESSION_POINT_CLOUD_POINT_CLOUD_ENCODER_H_
Definition attributes_encoder.h:29
Definition encoder_buffer.h:29
Definition point_attribute.h:33
const EncoderOptions * options() const
Definition point_cloud_encoder.h:76
void set_num_encoded_points(size_t num_points)
Definition point_cloud_encoder.h:121
virtual bool EncodeAttributesEncoderIdentifier(int32_t)
Definition point_cloud_encoder.h:111
int AddAttributesEncoder(std::unique_ptr< AttributesEncoder > att_enc)
Definition point_cloud_encoder.h:60
virtual Status EncodeGeometryData()
Definition point_cloud_encoder.h:88
virtual bool EncodePointAttributes()
Definition point_cloud_encoder.cc:103
PointCloudEncoder()
Definition point_cloud_encoder.cc:23
virtual EncodedGeometryType GetGeometryType() const
Definition point_cloud_encoder.h:41
const PointCloud * point_cloud() const
Definition point_cloud_encoder.h:77
size_t num_encoded_points() const
Definition point_cloud_encoder.h:50
virtual bool InitializeEncoder()
Definition point_cloud_encoder.h:82
virtual bool EncodeEncoderData()
Definition point_cloud_encoder.h:85
bool MarkParentAttribute(int32_t parent_att_id)
Definition point_cloud_encoder.cc:172
int num_attributes_encoders() const
Definition point_cloud_encoder.h:52
virtual bool GenerateAttributesEncoders()
Definition point_cloud_encoder.cc:148
const PointAttribute * GetPortableAttribute(int32_t point_attribute_id)
Definition point_cloud_encoder.cc:185
AttributesEncoder * attributes_encoder(int i)
Definition point_cloud_encoder.h:55
EncoderBuffer * buffer()
Definition point_cloud_encoder.h:75
virtual bool GenerateAttributesEncoder(int32_t att_id)=0
Status Encode(const EncoderOptions &options, EncoderBuffer *out_buffer)
Definition point_cloud_encoder.cc:30
virtual ~PointCloudEncoder()=default
virtual void ComputeNumberOfEncodedPoints()=0
void SetPointCloud(const PointCloud &pc)
Definition point_cloud_encoder.cc:26
virtual uint8_t GetEncodingMethod() const =0
virtual bool EncodeAllAttributes()
Definition point_cloud_encoder.cc:163
Definition point_cloud.h:29
Definition status.h:25
Definition attribute_octahedron_transform.cc:21
EncodedGeometryType
Definition compression_shared.h:41
@ POINT_CLOUD
Definition compression_shared.h:43
Status OkStatus()
Definition status.h:66
EncoderOptionsBase< int32_t > EncoderOptions
Definition encoder_options.h:97