Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sequential_attribute_encoder.h « attributes « compression « draco « src « dracoenc « draco « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 540ba94707777b04874050913162ad4c86d6ac59 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// 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_SEQUENTIAL_ATTRIBUTE_ENCODER_H_
#define DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_ATTRIBUTE_ENCODER_H_

#include "draco/compression/attributes/prediction_schemes/prediction_scheme_interface.h"
#include "draco/compression/point_cloud/point_cloud_encoder.h"

namespace draco {

// A base class for encoding attribute values of a single attribute using a
// given sequence of point ids. The default implementation encodes all attribute
// values directly to the buffer but derived classes can perform any custom
// encoding (such as quantization) by overriding the EncodeValues() method.
class SequentialAttributeEncoder {
 public:
  SequentialAttributeEncoder();
  virtual ~SequentialAttributeEncoder() = default;

  // Method that can be used for custom initialization of an attribute encoder,
  // such as creation of prediction schemes and initialization of attribute
  // encoder dependencies.
  // |encoder| is the parent PointCloudEncoder,
  // |attribute_id| is the id of the attribute that is being encoded by this
  // encoder.
  // This method is automatically called by the PointCloudEncoder after all
  // attribute encoders are created and it should not be called explicitly from
  // other places.
  virtual bool Init(PointCloudEncoder *encoder, int attribute_id);

  // Initialization for a specific attribute. This can be used mostly for
  // standalone encoding of an attribute without an PointCloudEncoder.
  virtual bool InitializeStandalone(PointAttribute *attribute);

  // Transforms attribute data into format that is going to be encoded
  // losslessly. The transform itself can be lossy.
  virtual bool TransformAttributeToPortableFormat(
      const std::vector<PointIndex> &point_ids);

  // Performs lossless encoding of the transformed attribute data.
  virtual bool EncodePortableAttribute(const std::vector<PointIndex> &point_ids,
                                       EncoderBuffer *out_buffer);

  // Encodes any data related to the portable attribute transform.
  virtual bool EncodeDataNeededByPortableTransform(EncoderBuffer *out_buffer);

  virtual bool IsLossyEncoder() const { return false; }

  int NumParentAttributes() const {
    return static_cast<int>(parent_attributes_.size());
  }
  int GetParentAttributeId(int i) const { return parent_attributes_[i]; }

  const PointAttribute *GetPortableAttribute() const {
    if (portable_attribute_ != nullptr)
      return portable_attribute_.get();
    return attribute();
  }

  // Called when this attribute encoder becomes a parent encoder of another
  // encoder.
  void MarkParentAttribute();

  virtual uint8_t GetUniqueId() const {
    return SEQUENTIAL_ATTRIBUTE_ENCODER_GENERIC;
  }

  const PointAttribute *attribute() const { return attribute_; }
  int attribute_id() const { return attribute_id_; }
  PointCloudEncoder *encoder() const { return encoder_; }

 protected:
  // Should be used to initialize newly created prediction scheme.
  // Returns false when the initialization failed (in which case the scheme
  // cannot be used).
  virtual bool InitPredictionScheme(PredictionSchemeInterface *ps);

  // Sets parent attributes for a given prediction scheme. Must be called
  // after all prediction schemes are initialized, but before the prediction
  // scheme is used.
  virtual bool SetPredictionSchemeParentAttributes(
      PredictionSchemeInterface *ps);

  // Encodes all attribute values in the specified order. Should be overridden
  // for specialized  encoders.
  virtual bool EncodeValues(const std::vector<PointIndex> &point_ids,
                            EncoderBuffer *out_buffer);

  bool is_parent_encoder() const { return is_parent_encoder_; }

  void SetPortableAttribute(std::unique_ptr<PointAttribute> att) {
    portable_attribute_ = std::move(att);
  }

  // Returns a mutable attribute that should be filled by derived encoders with
  // the transformed version of the attribute data. To get a public const
  // version, use the GetPortableAttribute() method.
  PointAttribute *portable_attribute() { return portable_attribute_.get(); }

 private:
  PointCloudEncoder *encoder_;
  const PointAttribute *attribute_;
  int attribute_id_;

  // List of attribute encoders that need to be encoded before this attribute.
  // E.g. The parent attributes may be used to predict values used by this
  // attribute encoder.
  std::vector<int32_t> parent_attributes_;

  bool is_parent_encoder_;

  // Attribute that stores transformed data from the source attribute after it
  // is processed through the ApplyTransform() method. Attribute data stored
  // within this attribute is guaranteed to be encoded losslessly and it can be
  // safely used for prediction of other attributes.
  std::unique_ptr<PointAttribute> portable_attribute_;
};

}  // namespace draco

#endif  // DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_ATTRIBUTE_ENCODER_H_