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

sequential_attribute_encoders_controller.cc « attributes « compression « draco « src « draco « draco « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7d5d1eeff263b670c72f36440f7ae921b6f812db (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// 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.
//
#include "draco/compression/attributes/sequential_attribute_encoders_controller.h"
#ifdef DRACO_NORMAL_ENCODING_SUPPORTED
#include "draco/compression/attributes/sequential_normal_attribute_encoder.h"
#endif
#include "draco/compression/attributes/sequential_quantization_attribute_encoder.h"
#include "draco/compression/point_cloud/point_cloud_encoder.h"

namespace draco {

SequentialAttributeEncodersController::SequentialAttributeEncodersController(
    std::unique_ptr<PointsSequencer> sequencer)
    : sequencer_(std::move(sequencer)) {}

SequentialAttributeEncodersController::SequentialAttributeEncodersController(
    std::unique_ptr<PointsSequencer> sequencer, int point_attrib_id)
    : AttributesEncoder(point_attrib_id), sequencer_(std::move(sequencer)) {}

bool SequentialAttributeEncodersController::Init(PointCloudEncoder *encoder,
                                                 const PointCloud *pc) {
  if (!AttributesEncoder::Init(encoder, pc)) {
    return false;
  }
  if (!CreateSequentialEncoders()) {
    return false;
  }
  // Initialize all value encoders.
  for (uint32_t i = 0; i < num_attributes(); ++i) {
    const int32_t att_id = GetAttributeId(i);
    if (!sequential_encoders_[i]->Init(encoder, att_id)) {
      return false;
    }
  }
  return true;
}

bool SequentialAttributeEncodersController::EncodeAttributesEncoderData(
    EncoderBuffer *out_buffer) {
  if (!AttributesEncoder::EncodeAttributesEncoderData(out_buffer)) {
    return false;
  }
  // Encode a unique id of every sequential encoder.
  for (uint32_t i = 0; i < sequential_encoders_.size(); ++i) {
    out_buffer->Encode(sequential_encoders_[i]->GetUniqueId());
  }
  return true;
}

bool SequentialAttributeEncodersController::EncodeAttributes(
    EncoderBuffer *buffer) {
  if (!sequencer_ || !sequencer_->GenerateSequence(&point_ids_)) {
    return false;
  }
  return AttributesEncoder::EncodeAttributes(buffer);
}

bool SequentialAttributeEncodersController::
    TransformAttributesToPortableFormat() {
  for (uint32_t i = 0; i < sequential_encoders_.size(); ++i) {
    if (!sequential_encoders_[i]->TransformAttributeToPortableFormat(
            point_ids_)) {
      return false;
    }
  }
  return true;
}

bool SequentialAttributeEncodersController::EncodePortableAttributes(
    EncoderBuffer *out_buffer) {
  for (uint32_t i = 0; i < sequential_encoders_.size(); ++i) {
    if (!sequential_encoders_[i]->EncodePortableAttribute(point_ids_,
                                                          out_buffer)) {
      return false;
    }
  }
  return true;
}

bool SequentialAttributeEncodersController::
    EncodeDataNeededByPortableTransforms(EncoderBuffer *out_buffer) {
  for (uint32_t i = 0; i < sequential_encoders_.size(); ++i) {
    if (!sequential_encoders_[i]->EncodeDataNeededByPortableTransform(
            out_buffer)) {
      return false;
    }
  }
  return true;
}

bool SequentialAttributeEncodersController::CreateSequentialEncoders() {
  sequential_encoders_.resize(num_attributes());
  for (uint32_t i = 0; i < num_attributes(); ++i) {
    sequential_encoders_[i] = CreateSequentialEncoder(i);
    if (sequential_encoders_[i] == nullptr) {
      return false;
    }
    if (i < sequential_encoder_marked_as_parent_.size()) {
      if (sequential_encoder_marked_as_parent_[i]) {
        sequential_encoders_[i]->MarkParentAttribute();
      }
    }
  }
  return true;
}

std::unique_ptr<SequentialAttributeEncoder>
SequentialAttributeEncodersController::CreateSequentialEncoder(int i) {
  const int32_t att_id = GetAttributeId(i);
  const PointAttribute *const att = encoder()->point_cloud()->attribute(att_id);

  switch (att->data_type()) {
    case DT_UINT8:
    case DT_INT8:
    case DT_UINT16:
    case DT_INT16:
    case DT_UINT32:
    case DT_INT32:
      return std::unique_ptr<SequentialAttributeEncoder>(
          new SequentialIntegerAttributeEncoder());
    case DT_FLOAT32:
      if (encoder()->options()->GetAttributeInt(att_id, "quantization_bits",
                                                -1) > 0) {
#ifdef DRACO_NORMAL_ENCODING_SUPPORTED
        if (att->attribute_type() == GeometryAttribute::NORMAL) {
          // We currently only support normals with float coordinates
          // and must be quantized.
          return std::unique_ptr<SequentialAttributeEncoder>(
              new SequentialNormalAttributeEncoder());
        } else {
#endif
          return std::unique_ptr<SequentialAttributeEncoder>(
              new SequentialQuantizationAttributeEncoder());
#ifdef DRACO_NORMAL_ENCODING_SUPPORTED
        }
#endif
      }
      break;
    default:
      break;
  }
  // Return the default attribute encoder.
  return std::unique_ptr<SequentialAttributeEncoder>(
      new SequentialAttributeEncoder());
}

}  // namespace draco